]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | Parson ( http://kgabis.github.com/parson/ ) | |
3 | Copyright (c) 2012 Krzysztof Gabis | |
4 | ||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 | of this software and associated documentation files (the "Software"), to deal | |
7 | in the Software without restriction, including without limitation the rights | |
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | copies of the Software, and to permit persons to whom the Software is | |
10 | furnished to do so, subject to the following conditions: | |
11 | ||
12 | The above copyright notice and this permission notice shall be included in | |
13 | all copies or substantial portions of the Software. | |
14 | ||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
21 | THE SOFTWARE. | |
22 | */ | |
23 | ||
24 | #ifndef parson_parson_h | |
25 | #define parson_parson_h | |
26 | ||
27 | #ifdef __cplusplus | |
28 | extern "C" | |
29 | { | |
30 | #endif | |
31 | ||
32 | #include <stddef.h> /* size_t */ | |
33 | ||
34 | /* Types and enums */ | |
35 | typedef struct json_object_t JSON_Object; | |
36 | typedef struct json_array_t JSON_Array; | |
37 | typedef struct json_value_t JSON_Value; | |
38 | ||
39 | typedef enum json_value_type { | |
40 | JSONError = 0, | |
41 | JSONNull = 1, | |
42 | JSONString = 2, | |
43 | JSONNumber = 3, | |
44 | JSONObject = 4, | |
45 | JSONArray = 5, | |
46 | JSONBoolean = 6 | |
47 | } JSON_Value_Type; | |
48 | ||
49 | /* Parses first JSON value in a file, returns NULL in case of error */ | |
50 | JSON_Value * json_parse_file(const char *filename); | |
51 | ||
52 | /* Parses first JSON value in a string, returns NULL in case of error */ | |
53 | JSON_Value * json_parse_string(const char *string); | |
54 | ||
55 | /* JSON Object */ | |
56 | JSON_Value * json_object_get_value (const JSON_Object *object, const char *name); | |
57 | const char * json_object_get_string (const JSON_Object *object, const char *name); | |
58 | JSON_Object * json_object_get_object (const JSON_Object *object, const char *name); | |
59 | JSON_Array * json_object_get_array (const JSON_Object *object, const char *name); | |
60 | double json_object_get_number (const JSON_Object *object, const char *name); | |
61 | int json_object_get_boolean(const JSON_Object *object, const char *name); | |
62 | ||
63 | /* dotget functions enable addressing values with dot notation in nested objects, | |
64 | just like in structs or c++/java/c# objects (e.g. objectA.objectB.value). | |
65 | Because valid names in JSON can contain dots, some values may be inaccessible | |
66 | this way. */ | |
67 | JSON_Value * json_object_dotget_value (const JSON_Object *object, const char *name); | |
68 | const char * json_object_dotget_string (const JSON_Object *object, const char *name); | |
69 | JSON_Object * json_object_dotget_object (const JSON_Object *object, const char *name); | |
70 | JSON_Array * json_object_dotget_array (const JSON_Object *object, const char *name); | |
71 | double json_object_dotget_number (const JSON_Object *object, const char *name); | |
72 | int json_object_dotget_boolean(const JSON_Object *object, const char *name); | |
73 | ||
74 | /* Functions to get available names */ | |
75 | size_t json_object_get_count(const JSON_Object *object); | |
76 | const char * json_object_get_name (const JSON_Object *object, size_t index); | |
77 | ||
78 | /* JSON Array */ | |
79 | JSON_Value * json_array_get_value (const JSON_Array *array, size_t index); | |
80 | const char * json_array_get_string (const JSON_Array *array, size_t index); | |
81 | JSON_Object * json_array_get_object (const JSON_Array *array, size_t index); | |
82 | JSON_Array * json_array_get_array (const JSON_Array *array, size_t index); | |
83 | double json_array_get_number (const JSON_Array *array, size_t index); | |
84 | int json_array_get_boolean(const JSON_Array *array, size_t index); | |
85 | size_t json_array_get_count (const JSON_Array *array); | |
86 | ||
87 | /* JSON Value */ | |
88 | JSON_Value_Type json_value_get_type (const JSON_Value *value); | |
89 | JSON_Object * json_value_get_object (const JSON_Value *value); | |
90 | JSON_Array * json_value_get_array (const JSON_Value *value); | |
91 | const char * json_value_get_string (const JSON_Value *value); | |
92 | double json_value_get_number (const JSON_Value *value); | |
93 | int json_value_get_boolean(const JSON_Value *value); | |
94 | void json_value_free (JSON_Value *value); | |
95 | ||
96 | #ifdef __cplusplus | |
97 | } | |
98 | #endif | |
99 | ||
100 | #endif |