|
@@ -43,25 +43,46 @@ int encode(){
|
|
|
ini_encoder(&json);
|
|
|
add_string(&json, "name", "robert");
|
|
|
add_number(&json, "nb", 25.698, 2);
|
|
|
- add_integer(&json, "int", 84);
|
|
|
+ add_integer(&json, "int", 846);
|
|
|
add_string(&json, "aze", "rty");
|
|
|
add_boolean(&json, "bool", false);
|
|
|
add_value(&json, "\"test\": \"aze\nrty\"");
|
|
|
- char * str;
|
|
|
- str = json_encode(&json);
|
|
|
- printf("%s\n", str);
|
|
|
- clean_json_encoder(&json);
|
|
|
+ printf("Json\n");
|
|
|
+ printf("%s\n", json_encode(&json));
|
|
|
+
|
|
|
+ //Encode un JsonEncoder
|
|
|
+ JsonEncoder json2;
|
|
|
+ ini_encoder(&json2);
|
|
|
+ add_integer(&json2, "vie", 42);
|
|
|
+ add_object(&json2, "obj", json);
|
|
|
+ printf("\nJson 2\n");
|
|
|
+ printf("%s\n", json_encode(&json2));
|
|
|
|
|
|
//Decode
|
|
|
- JsonParser parser;
|
|
|
+ JsonParser parser, *parser2;
|
|
|
char* key, *val;
|
|
|
- json_parse(&parser, str);
|
|
|
+ json_parse(&parser, json_encode(&json2));
|
|
|
//Affiche toutes les clefs : valeurs
|
|
|
+ printf("\nParser\n");
|
|
|
for(int i = 0; i < parser.elt; i++){
|
|
|
key = key_index(&parser, i);
|
|
|
val = get_index(&parser, i);
|
|
|
printf("%s : %s\n", key, val);
|
|
|
}
|
|
|
+ //Lecture du sous json
|
|
|
+ parser2 = get_object(&parser, "obj");
|
|
|
+ //Affiche toutes les clefs : valeurs
|
|
|
+ printf("\nParser 2\n");
|
|
|
+ for(int i = 0; i < parser2->elt; i++){
|
|
|
+ key = key_index(parser2, i);
|
|
|
+ val = get_index(parser2, i);
|
|
|
+ printf("%s : %s\n", key, val);
|
|
|
+ }
|
|
|
+
|
|
|
+ //Clean
|
|
|
+ clean_json_encoder(&json);
|
|
|
+ clean_json_encoder(&json2);
|
|
|
+ clean_json_parser(&parser);
|
|
|
|
|
|
return 0;
|
|
|
}
|