当前位置:首页 > Windows程序 > 正文

jsoncpp的api简要说明

2021-03-26 Windows程序

标签:

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简要说明

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/68095.html