| 180 |
182 |
| 181 CxJsonValue* cxJsonCreateInteger( |
183 CxJsonValue* cxJsonCreateInteger( |
| 182 const CxAllocator* allocator, int64_t num); |
184 const CxAllocator* allocator, int64_t num); |
| 183 |
185 |
| 184 CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, |
186 CxJsonValue* cxJsonCreateString(const CxAllocator* allocator, |
| 185 const char *str); |
187 AnyStr str); |
| 186 |
|
| 187 CxJsonValue* cxJsonCreateCxString( |
|
| 188 const CxAllocator* allocator, cxstring str); |
|
| 189 |
188 |
| 190 CxJsonValue* cxJsonCreateLiteral( |
189 CxJsonValue* cxJsonCreateLiteral( |
| 191 const CxAllocator* allocator, CxJsonLiteral lit); |
190 const CxAllocator* allocator, CxJsonLiteral lit); |
| 192 |
191 |
| 193 int cxJsonArrAddNumbers(CxJsonValue* arr, |
192 int cxJsonArrAddNumbers(CxJsonValue* arr, |
| 206 const CxJsonLiteral* lit, size_t count); |
205 const CxJsonLiteral* lit, size_t count); |
| 207 |
206 |
| 208 int cxJsonArrAddValues(CxJsonValue* arr, |
207 int cxJsonArrAddValues(CxJsonValue* arr, |
| 209 CxJsonValue* const* val, size_t count); |
208 CxJsonValue* const* val, size_t count); |
| 210 |
209 |
| 211 int cxJsonObjPut(CxJsonValue* obj, cxstring name, CxJsonValue* child); |
210 int cxJsonObjPut(CxJsonValue* obj, AnyStr name, CxJsonValue* child); |
| 212 |
211 |
| 213 CxJsonValue* cxJsonObjPutObj(CxJsonValue* obj, cxstring name); |
212 CxJsonValue* cxJsonObjPutObj(CxJsonValue* obj, AnyStr name); |
| 214 |
213 |
| 215 CxJsonValue* cxJsonObjPutArr(CxJsonValue* obj, cxstring name); |
214 CxJsonValue* cxJsonObjPutArr(CxJsonValue* obj, AnyStr name); |
| 216 |
215 |
| 217 CxJsonValue* cxJsonObjPutNumber(CxJsonValue* obj, |
216 CxJsonValue* cxJsonObjPutNumber(CxJsonValue* obj, |
| 218 cxstring name, double num); |
217 AnyStr name, double num); |
| 219 |
218 |
| 220 CxJsonValue* cxJsonObjPutInteger(CxJsonValue* obj, |
219 CxJsonValue* cxJsonObjPutInteger(CxJsonValue* obj, |
| 221 cxstring name, int64_t num); |
220 AnyStr name, int64_t num); |
| 222 |
221 |
| 223 CxJsonValue* cxJsonObjPutString(CxJsonValue* obj, |
222 CxJsonValue* cxJsonObjPutString(CxJsonValue* obj, |
| 224 cxstring name, const char* str); |
223 AnyStr name, AnyStr str); |
| 225 |
|
| 226 CxJsonValue* cxJsonObjPutCxString(CxJsonValue* obj, |
|
| 227 cxstring name, cxstring str); |
|
| 228 |
224 |
| 229 CxJsonValue* cxJsonObjPutLiteral(CxJsonValue* obj, |
225 CxJsonValue* cxJsonObjPutLiteral(CxJsonValue* obj, |
| 230 cxstring name, CxJsonLiteral lit); |
226 AnyStr name, CxJsonLiteral lit); |
| 231 ``` |
227 ``` |
| 232 |
228 |
| 233 The `cxJsonCreateXY()`-family of functions can be used to create JSON values which are allocated by the specified `allocator`. |
229 The `cxJsonCreateXY()`-family of functions can be used to create JSON values which are allocated by the specified `allocator`. |
| 234 If you specify `NULL` as allocator, the `cxDefaultAllocator` is used. |
230 If you specify `NULL` as allocator, the `cxDefaultAllocator` is used. |
| 235 |
231 |
| 254 The following example shows how to construct a complete JSON object. |
250 The following example shows how to construct a complete JSON object. |
| 255 |
251 |
| 256 ```C |
252 ```C |
| 257 CxJsonValue *obj = cxJsonCreateObj(NULL); |
253 CxJsonValue *obj = cxJsonCreateObj(NULL); |
| 258 |
254 |
| 259 cxJsonObjPutLiteral(obj, CX_STR("bool"), CX_JSON_FALSE); |
255 cxJsonObjPutLiteral(obj, "bool", CX_JSON_FALSE); |
| 260 cxJsonObjPutInteger(obj, CX_STR("int"), 47); |
256 cxJsonObjPutInteger(obj, "int", 47); |
| 261 |
257 |
| 262 CxJsonValue *strings = cxJsonObjPutArr(obj, CX_STR("strings")); |
258 CxJsonValue *strings = cxJsonObjPutArr(obj, "strings"); |
| 263 cxJsonArrAddStrings(strings, (const char*[]) {"hello", "world"}, 2); |
259 cxJsonArrAddStrings(strings, (const char*[]) {"hello", "world"}, 2); |
| 264 |
260 |
| 265 CxJsonValue *nested = cxJsonObjPutObj(obj, CX_STR("nested")); |
261 CxJsonValue *nested = cxJsonObjPutObj(obj, "nested"); |
| 266 CxJsonValue *objects = cxJsonObjPutArr(nested, CX_STR("objects")); |
262 CxJsonValue *objects = cxJsonObjPutArr(nested, "objects"); |
| 267 CxJsonValue *obj_in_arr[2] = { |
263 CxJsonValue *obj_in_arr[2] = { |
| 268 cxJsonCreateObj(NULL), |
264 cxJsonCreateObj(NULL), |
| 269 cxJsonCreateObj(NULL), |
265 cxJsonCreateObj(NULL), |
| 270 }; |
266 }; |
| 271 cxJsonObjPutInteger(obj_in_arr[0], CX_STR("name1"), 1); |
267 cxJsonObjPutInteger(obj_in_arr[0], "name1", 1); |
| 272 cxJsonObjPutInteger(obj_in_arr[0], CX_STR("name2"), 3); |
268 cxJsonObjPutInteger(obj_in_arr[0], "name2", 3); |
| 273 |
269 |
| 274 cxJsonObjPutInteger(obj_in_arr[1], CX_STR("name2"), 7); |
270 cxJsonObjPutInteger(obj_in_arr[1], "name2", 7); |
| 275 cxJsonObjPutInteger(obj_in_arr[1], CX_STR("name1"), 3); |
271 cxJsonObjPutInteger(obj_in_arr[1], "name1", 3); |
| 276 |
272 |
| 277 cxJsonArrAddValues(objects, obj_in_arr, 2); |
273 cxJsonArrAddValues(objects, obj_in_arr, 2); |
| 278 |
274 |
| 279 cxJsonArrAddNumbers(cxJsonObjPutArr(nested, CX_STR("floats")), |
275 cxJsonArrAddNumbers(cxJsonObjPutArr(nested, "floats"), |
| 280 (double[]){3.1415, 47.11, 8.15}, 3); |
276 (double[]){3.1415, 47.11, 8.15}, 3); |
| 281 |
277 |
| 282 cxJsonArrAddLiterals(cxJsonObjPutArr(nested, CX_STR("literals")), |
278 cxJsonArrAddLiterals(cxJsonObjPutArr(nested, "literals"), |
| 283 (CxJsonLiteral[]){CX_JSON_TRUE, CX_JSON_NULL, CX_JSON_FALSE}, 3); |
279 (CxJsonLiteral[]){CX_JSON_TRUE, CX_JSON_NULL, CX_JSON_FALSE}, 3); |
| 284 |
280 |
| 285 CxJsonValue *ints = cxJsonObjPutArr(nested, CX_STR("ints")); |
281 CxJsonValue *ints = cxJsonObjPutArr(nested, "ints"); |
| 286 cxJsonArrAddIntegers(ints, (int64_t[]){4, 8, 15}, 3); |
282 cxJsonArrAddIntegers(ints, (int64_t[]){4, 8, 15}, 3); |
| 287 |
283 |
| 288 CxJsonValue *nested_array = cxJsonCreateArr(NULL); |
284 CxJsonValue *nested_array = cxJsonCreateArr(NULL); |
| 289 cxJsonArrAddValues(ints, &nested_array, 1); |
285 cxJsonArrAddValues(ints, &nested_array, 1); |
| 290 cxJsonArrAddIntegers(nested_array, (int64_t[]){16, 23}, 2); |
286 cxJsonArrAddIntegers(nested_array, (int64_t[]){16, 23}, 2); |