2
Copyright (c) 2009 Dave Gamble
3
Copyright (c) 2009 The OpenTyrian Development Team
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:
12
The above copyright notice and this permission notice shall be included in
13
all copies or substantial portions of the Software.
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
49
cJSON_Type type; // type of this item
51
// next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem
52
struct cJSON *next, *prev; // sibling items in chain (parent item is array or object)
53
struct cJSON *child; // chain of child items (this item is array or object)
55
char *string; // identifying string of this item (parent item is object)
57
char *valuestring; // The item's string, if type==cJSON_String
58
int valueint; // The item's number, if type==cJSON_Number
59
double valuedouble; // The item's number, if type==cJSON_Number
64
// Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished.
65
cJSON *cJSON_Parse(const char *value);
66
// Render a cJSON entity to text for transfer/storage. Free the char* when finished.
67
char *cJSON_Print(cJSON *item);
68
// Delete a cJSON entity and all subentities.
69
void cJSON_Delete(cJSON *c);
71
// Returns the number of items in an array (or object).
72
int cJSON_GetArraySize(cJSON *array);
73
// Retrieve item number "item" from array "array". Returns NULL if unsuccessful.
74
cJSON *cJSON_GetArrayItem(cJSON *array,int item);
75
// Get item "string" from object. Case insensitive.
76
cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
78
cJSON *cJSON_CreateOrGetObjectItem( cJSON *object, const char *string );
80
// These calls create a cJSON item of the appropriate type.
81
cJSON *cJSON_CreateNull( void );
82
cJSON *cJSON_CreateBoolean( bool );
83
cJSON *cJSON_CreateNumber( double );
84
cJSON *cJSON_CreateString( const char * );
85
cJSON *cJSON_CreateArray( void );
86
cJSON *cJSON_CreateObject( void );
88
void cJSON_ForceType( cJSON *, cJSON_Type );
90
void cJSON_SetBoolean( cJSON *, bool );
91
void cJSON_SetNumber( cJSON *, double );
92
void cJSON_SetString( cJSON *, const char * );
94
// These utilities create an Array of count items.
95
cJSON *cJSON_CreateIntArray(int *numbers,int count);
96
cJSON *cJSON_CreateFloatArray(float *numbers,int count);
97
cJSON *cJSON_CreateDoubleArray(double *numbers,int count);
98
cJSON *cJSON_CreateStringArray(const char **strings,int count);
100
// Append item to the specified array/object.
101
void cJSON_AddItemToArray(cJSON *array, cJSON *item);
102
void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
104
#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
105
#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
106
#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
107
#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
108
#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
110
void cJSON_ClearArray( cJSON *array );
111
#define cJSON_ClearObject( object ) cJSON_ClearArray(object)