json中的数组操作

原文地址 点击打开链接

使用json-c组装json数据比解析json数据稍微简单一些,此部分API在一定程度上提供了内存自动化管理的功能,使用起来比较方便:

#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;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值