Transferred from: http://blog.csdn.net/chenzhongjing/article/details/9188347
: http://Sourceforge.net/projects/cjson/files/?source=navbarExample 1: Create a simple array of student information Cjson* Proot =Cjson_createobject (); Cjson* Parray =Cjson_createarray (); Cjson_additemtoobject (Proot,"Students_info", Parray); Char* Szout =Cjson_print (proot); Cjson* Pitem =Cjson_createobject (); Cjson_addstringtoobject (Pitem,"name","chenzhongjing"); Cjson_addstringtoobject (Pitem,"Sex","male"); Cjson_addnumbertoobject (Pitem," Age", -); Cjson_additemtoarray (Parray, Pitem); Pitem=Cjson_createobject (); Cjson_addstringtoobject (Pitem,"name","Fengxuan"); Cjson_addstringtoobject (Pitem,"Sex","male"); Cjson_addnumbertoobject (Pitem," Age", -); Cjson_additemtoarray (Parray, Pitem); Pitem=Cjson_createobject (); Cjson_addstringtoobject (Pitem,"name","Tuhui"); Cjson_addstringtoobject (Pitem,"Sex","male"); Cjson_addnumbertoobject (Pitem," Age", A); Cjson_additemtoarray (Parray, Pitem); Char* Szjson =Cjson_print (proot); Cjson_delete (proot);//Free (Szjson);Proot=Cjson_parse (Szjson); Parray= Cjson_getobjectitem (Proot,"Students_info"); if(NULL = =Parray) { return-1; } intICount =cjson_getarraysize (parray); for(inti =0; i < ICount; ++i) {Cjson* Pitem =Cjson_getarrayitem (Parray, i); if(NULL = =pitem) { Continue; } stringStrName = Cjson_getobjectitem (Pitem,"name"),valuestring; stringStrsex = Cjson_getobjectitem (Pitem,"Sex"),valuestring; intIage = Cjson_getobjectitem (Pitem," Age"),Valueint;} Cjson_delete (Proot); Free(Szjson);
Cjson: A simple and useful JSON parser written in C