【发布时间】:2018-01-04 09:30:15
【问题描述】:
我有这样一个json字符串:
{"status":0,"bridge_id":"bridge.1","b_party":"85267191234","ref_id":"20180104151432001_0","function":{"operator_profile":{"operator":"aaa.bbb"},"subscriber_profile":{"is_allowed":true,"type":8},"name":"ServiceAuthen.Ack"},"node_id":"aaa.bbb.collector.1"}
如何将其读入 jsoncpp lib 的 Json::Value 对象?
我通过搜索stackoverflow找到了这样的代码:
std::string strJson = "{\"mykey\" : \"myvalue\"}"; // need escape the quotes
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse( strJson.c_str(), root ); //parse process
if ( !parsingSuccessful )
{
std::cout << "Failed to parse"
<< reader.getFormattedErrorMessages();
return 0;
}
std::cout << root.get("mykey", "A Default Value if not exists" ).asString() << std::endl;
return 0;
但是如何将我的字符串转换为这种形式?
{\"mykey\" : \"myvalue\"}
感谢您的帮助。
【问题讨论】:
标签: jsoncpp