我的网络服务中有一个返回字符串:
std::string json_str = "{"Count":18,"Result":[{"Description":"DATABASE TASK MODE VALUE","Name":"TASK","Val":24,"addID":0,"CreatedAt":"2015-08-12T17:57:03.954Z","ModifiedAt":"2015-08-13T20:41:30.900Z","CreatedBy":"00000000-0000-0000-0000-000000000000","ModifiedBy":"00000000-0000-0000-0000-000000000000","Owner":"00000000-0000-0000-0000-000000000000","Id":"89fb5320-411b-11e5-a0dc-8babbc75a180","Meta":{"Permissions":{"CanRead":true,"CanUpdate":true,"CanDelete":true}}}, ...etc ]}"
此代码有效
document.Parse(json_str.c_str()).HasParseError())
assert(document.IsObject());
rapidjson::Value::MemberIterator localdata_0 = document.FindMember("89fb5320-411b-11e5-a0dc-8babbc75a180");
但是在这些方面失败了
assert(localdata_0 != document.MemberEnd());
assert(localdata_0->value.IsDouble());
有没有一种简单的方法可以将我的字符串格式化为正确的json格式?
const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } ";
答案 0 :(得分:0)
解决方案是将字符串切割成行并进行解析。将每个字符串行放入向量中。
constexpr