-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestjson.c
34 lines (26 loc) · 886 Bytes
/
testjson.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* File: testjson.c
* Author: bisj
*
* Created on den 23 september 2014, 09:09
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
int main(void){
cJSON* root = cJSON_CreateObject();
cJSON_AddStringToObject(root, "name", "billy");
cJSON_AddFalseToObject(root, "bool1");
cJSON_AddTrueToObject(root, "bool2");
cJSON_AddNullToObject(root, "nullable");
cJSON_AddNumberToObject(root, "number", 12);
cJSON_AddItemToObject(root, "child", cJSON_CreateObject());
cJSON_AddItemToObject(root, "childArray", cJSON_CreateArray());
cJSON* childArray = cJSON_GetObjectItem(root, "childArray");
//BEhöver vi ha koll på om parent är en array??
cJSON* childObject = cJSON_CreateObject();
cJSON_AddItemToArray(childArray, childObject);
printf(cJSON_Print(root));
return 0;
}