jsoncpp使用

1.下载jsoncpp:
  http://jsoncpp.sourceforge.net/这个网页上不仅有下载链接,还有使用范例
下载页面为:http://sourceforge.net/projects/jsoncpp/files/
我下载的是:jsoncpp-src-0.5.0.tar.gz

2.编译:解压缩jsoncpp-src-0.5.0.tar.gz,按照http://jsoncpp.sourceforge.net/网页中的README文档(在Build instructions下面有个链接)操作。
首先下载scons-1.2.0
http://sourceforge.net/projects/scons/files/scons-local/1.2.0/
将scons-local-1.2.0.tar.gz解压到jsoncpp根目录下,让jsoncpp README文档和scons.py在同一级目录下,然后执行编译(因为我的机器原来安装过python,如果之前没有安装python的朋友需要先安装)
python scons.py platform="linux-gcc"
如果想添加新的platform选项,按照README的指导“Adding platform is fairly simple. You need to change the Sconstruct file to do so.”


3.使用:
包含头文件
#include "json/json.h"
编译应用程序的时候指定链接库和路径,如:-L../jsoncpp-src-0.5.0/libs/linux-gcc-4.4.3 -ljson_linux-gcc-4.4.3_libmt


示例代码:

#include "json/json.h"

void parseJson()
{
    std::string strValue=
    "{\"location\": {\"city\":\"Cedar Rapids\"}, \"current_observation\":{\"temperature_string\":\"42.6F\"}}";
    Json::Reader reader;
    Json::Value value;
    std:string city, temp;

    if (reader.parse(strValue, value))
    
        city = value["location"]["city"].asString();
        temp = value["current_observation"]["temperature_string"].asString();
        printf("city is :%s\nTemperature is:%s\n", city.c_str(), temp.c_str());
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值