#include <stdio.h> #include <string.h> #include <json.h>int main (int Argc,char **argv) { 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 ()); 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); const Char *str=json_object_to_json_string (JSON); printf ("%s\n", str); Json_object_put (JSON); return 0;}
- Json_test:json_test.c
- Cc-g-d__strict_ansi__-ljson-i/usr/local/include/json/-l/usr/local/lib/json_test.c-o json_test
One of the-d__strict_ansi__ is to eliminate the C99 compilation options.
Json-c code Example