#include "stdafx.h"
#include "Json-c/json.h"
int _tmain (int argc, _tchar* argv[])
{
Normal JSON format
Json_object *json = Json_object_new_object ();
Json_object_object_add (JSON, "name", Json_object_new_string ("Laomeng"));
Json_object_object_add (JSON, "email", json_object_new_string ("[email protected]");
Json_object_object_add (JSON, "age", Json_object_new_int (30));
Produces a JSON array format
Json_object *tech = Json_object_new_array ();
Json_object_array_add (Tech, json_object_new_string ("C"));
Json_object_array_add (Tech, json_object_new_string ("C + +"));
Json_object_array_add (Tech, json_object_new_string ("PHP"));
Json_object_object_add (JSON, "technology", tech);
The data contains the normal JSON format
Json_object *TECH2 = Json_object_new_array ();
Json_object *json_sub = Json_object_new_object ();
Json_object_object_add (json_sub, "name", Json_object_new_string ("Laomeng"));
Json_object_object_add (json_sub, "email", json_object_new_string ("[email protected]");
Json_object_object_add (Json_sub, "Age", Json_object_new_int (30));
Json_object_array_add (TECH2, json_sub);
Json_object_object_add (JSON, "Technology2", TECH2);
Output
const char *STR = json_object_to_json_string (JSON);
/*
{"Name": "Laomeng", "email": "[email protected]", "age": +, "technology": ["C", "C + +", "PHP"], "technology2": [{"Nam E ":" Laomeng "," email ":" [email protected] "," Age ": 30}]}
*/
printf ("%s\n", str);
Json_object_put (JSON);
return 0;
}
Compile the Json-c library under VS2013 and simply generate JSON-formatted data