码迷,mamicode.com
首页 > Web开发 > 详细

json-c代码示例

时间:2016-04-13 00:06:23      阅读:362      评论:0      收藏:0      [点我收藏+]

标签:

#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("laomeng188@163.com"));

    json_object_object_add(json,

            "age",json_object_new_int(30));

    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;

}

 

  1. json_test:json_test.c  
  2. cc -g -D__STRICT_ANSI__ -ljson -I/usr/local/include/json/ -L/usr/local/lib/ json_test.c -o json_test 
    其中 -D__STRICT_ANSI__ 是为了消除c99的编译选项。

json-c代码示例

标签:

原文地址:http://www.cnblogs.com/flintlovesam/p/5384948.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!