JSON-C能让你在C语言里轻松创建JSON对象,输出JSON字符串,解析JSON字符串成JSON对象。
test1.c的部分实例代码:
- struct json_object *my_array;
- my_array = json_object_new_array();
- json_object_array_add(my_array, json_object_new_int(1));
- json_object_array_add(my_array, json_object_new_int(2));
- json_object_array_add(my_array, json_object_new_int(3));
- json_object_array_put_idx(my_array, 4, json_object_new_int(5));
- printf("my_array=\n");
- for(i=0; i < json_object_array_length(my_array); i++) {
- struct json_object *obj = json_object_array_get_idx(my_array, i);
- printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
- }
- printf("my_array.to_string()=%s\n", json_object_to_json_string(my_array));
地址: http://oss.metaparadigm.com/json-c/
[Original] JSON-C implements a reference counting object model that allows you to easily construct JSON objects in C, output them as JSON formatted strings and parse JSON formatted strings back into the C representation of JSON objects.
Copyright Metaparadigm Pte. Ltd. 2004, 2005. Michael Clark