JsonCpp
发布时间:2020-12-16 19:48:24 所属栏目:百科 来源:网络整理
导读:官网地址: https://github.com/open-source-parsers/jsoncpp 一个简单测试: void test_jsoncpp() { std::string jsoncppstring; //写: { Json::StyledWriter writer; Json::Value jmessage; jmessage["test_strkey1"] = "value1"; jmessage["test_strkey2
官网地址: https://github.com/open-source-parsers/jsoncpp 一个简单测试: void test_jsoncpp() //写: {Json::StyledWriter writer; Json::Value jmessage; jmessage["test_strkey1"] = "value1"; jmessage["test_strkey2"] = "value2"; jmessage["test_strkey3"] = "value3"; jmessage["test_intkey1"] = 100; std::string strJsonCpp = writer.write(jmessage); jsoncppstring = strJsonCpp; OutputDebugStringA(strJsonCpp.c_str()); } //读取: { Json::Reader reader; Json::Value jmessage; if (!reader.parse(jsoncppstring,jmessage)) { RTC_LOG(WARNING) << "Received unknown message. " << jsoncppstring; return; } std::string type_str; std::string json_object; rtc::GetStringFromJsonObject(jmessage,"test_strkey1",&type_str); int type_int; bool b = rtc::GetIntFromJsonObject(jmessage,&type_int); if (!b) { //return; } //遍历: Json::Value::iterator itr = jmessage.begin(); for ( int n = 0; n<jmessage.size(); n++) { const Json::UInt i = itr.index(); const Json::Value jvalue = itr.key(); std::string str = itr.memberName(); const bool b1 = jvalue.isBool(); const bool b2 = jvalue.isString(); const bool b3 = jvalue.isArray(); if (b1 == true) { bool b = jvalue.asBool(); } if (b2 == true) { std::string str = jvalue.asString() } if (b3 == true) { } if (i) { } itr++; } } //获取key value: for ( int n = 0; n<vectorStrMember.size(); n++) } 转一遍文章: 《Jsoncpp的使用》 from:https://blog.csdn.net/luxiaoyu_sdc/article/details/9276705 JSON建构于两种结构:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |