I'm using a cjson:http://sourceforge.net/projects/cjson/.
Look at the JSON data structure first
No objects in C, so JSON data is stored in a linked list
C Code typedef struct cjson { struct cjson *next,*prev; // array Object data used in struct cjson *child; // array and objects point to the child array object or value int type; // type of element, if object or array char *valuestring; // if it is a string int valueint; // If it's numerical double valuedouble; // If the type is cjson_number char *string; // the item ' s name String, if this item is the child of, or is in the list of subitems of an object. } cjson;
Like you have a JSON data
JavaScript code {"Name": "Jack (\" bee\ ") nimble", "format": {"type": "Rect", "wid Th ": 1920," height ": 1080," Interlace ": false," frame rate ": 24}}
Then you can
1: The string is parsed into a JSON structure.
C code Cjson *root = Cjson_parse (my_json_string);
2: Get an Element
C code Cjson *format = Cjson_getobjectitem (root, "format"); int framerate = Cjson_getobjectitem (format, frame rate)->valueint;
3: The JSON structure is converted to a string
C Code char *rendered=cjson_print (root);
4: Delete
C code Cjson_delete (root);
5: Building a JSON structure
C code
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service