bianbian coding life

便便代码人生: 关注技术, 翻译文档, 偶尔动动手

[译]JSON的C语言实现: JSON-C - A JSON implementation in C

Posted by bianbian on 2006-12-17 15:44

本文Tags:

[翻译] JSON-C能让你在C语言里轻松创建JSON对象,输出JSON字符串,解析JSON字符串成JSON对象。
test1.c的部分实例代码:

  1. struct json_object *my_array;
  2.   my_array = json_object_new_array();
  3.   json_object_array_add(my_array, json_object_new_int(1));
  4.   json_object_array_add(my_array, json_object_new_int(2));
  5.   json_object_array_add(my_array, json_object_new_int(3));
  6.   json_object_array_put_idx(my_array, 4, json_object_new_int(5));
  7.   printf("my_array=\n");
  8.   for(i=0; i < json_object_array_length(my_array); i++) {
  9.     struct json_object *obj = json_object_array_get_idx(my_array, i);
  10.     printf("\t[%d]=%s\n", i, json_object_to_json_string(obj));
  11.   }
  12.   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

如果不清楚JSON,请参考:http://www.json.org

标签:

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

2 Responses to “[译]JSON的C语言实现: JSON-C - A JSON implementation in C”

  1. bianbian Says:

    试了一下,也支持中文。呵呵。倒是可以考虑用一下。

  2. Marshall Says:

    有的时候感觉JSON比XML好用得多~~一个eval就OK了

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

(required)