码迷,mamicode.com
首页 > Windows程序 > 详细

jsoncpp的api简要说明

时间:2015-08-26 11:54:55      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:

1  jsoncpp的api简要说明

1,解析(json字符串转为对象)

std::string strDataJson;

Json::Reader JReader; 

Json::Value JObject;

if (!JReader.parse(strDataJson, JObject))

{

cerr << "parse json error." << endl;

return bSuccess;

}

 

2,读取

std::string strMsg = JRec["msg"].asString();

int nRetCode = JRec["ret"]..asInt();

Json::Value JList = JRec["data"]["list"];

int nSize = JList.size();

 

获取错误信息: JReader.getFormatedErrorMessages()

 

3,增加或修改

JRoot["stringdata"] = Json::Value("msg");

JRoot["intdata"] = Json::Value(10);

 

4,删除

JValue.removeMember("toberemove");

 

5,对象转为字符串

//输出无格式json字符串

Json::FastWriter fast_writer;

strJRecList = fast_writer.write(JRoot);

 

//格式化之后的json,有回车换行符

std::string strOut = JRoot.toStyledString();

jsoncpp的api简要说明

标签:

原文地址:http://www.cnblogs.com/diegodu/p/4759935.html

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