jsoncpp Json::LogicError,当我尝试解析一个对象时
jsoncpp Json::LogicError, when I try to parse an object
我有一个Json字符串如下,我需要用jsoncpp C++库解析它们;但是,即使我尝试解析status_code最简单的键,我也会遇到逻辑错误。我解析 json 的代码是这样的:
Json::Value root = js;
const Json::Value status_code = root["status_code"];
其中 js 是一个 std::string。我打印根目录,结果似乎很正常,但第二行代码总是出错。另外,我尝试了Json::Value::get方法,没有任何变化。
{
"status_code": "OK",
"status_msg": "All images in request have completed successfully. ",
"meta": {
"tag": {
"timestamp": 1457008532.462851,
"model": "general-v1.3",
"config": "34fb1111b4d5f67cf1b8665ebc603704"
}
},
"results": [
{
"docid": 161641131401527616156105737996754786562,
"status_code": "OK",
"status_msg": "OK",
"local_id": "",
"result": {
"tag": {
"concept_ids": [
"ai_786Zr311",
"ai_pPxqdnP5",
"ai_Pf2b7clG",
"ai_c9n7SB25",
"ai_WTrlNkqM",
"ai_ggQlMG6W",
"ai_62K34TR4",
"ai_hf5ZBGcK",
"ai_9c0Hmcx0",
"ai_6lhccv44",
"ai_pCnxWJZh",
"ai_bmls4LpL",
"ai_TkWkj1sX",
"ai_rsX6XWc2",
"ai_x3vjxJsW",
"ai_4Qjv5PTH",
"ai_lrTHSPdB",
"ai_bBXFkGB1",
"ai_xxnGcd42",
"ai_PpTcwbdQ"
],
"classes": [
"no person",
"room",
"indoors",
"furniture",
"vehicle",
"industry",
"technology",
"production",
"exhibition",
"business",
"contemporary",
"group",
"container",
"building",
"home",
"modern",
"action",
"auto racing",
"seat",
"computer"
],
"probs": [
0.9784166812896729,
0.9754077196121216,
0.974927544593811,
0.9747141003608704,
0.9636767506599426,
0.954016923904419,
0.9406172633171082,
0.9292353391647339,
0.9243901968002319,
0.911110520362854,
0.8961678147315979,
0.8841571807861328,
0.8797860145568848,
0.8792335987091064,
0.869953989982605,
0.8654355406761169,
0.8574825525283813,
0.8546661734580994,
0.8530611991882324,
0.8511127829551697
]
}
},
"docid_str": "799af313d0500ce2648b9a4e20c49902"
}
]
}
我通过使用 Json::Reader 解决了我自己的问题。我正在发布代码以帮助将面临此问题的其他人。
我得到了带有以下代码片段的"类"标签:
Json::Value root;
Json::Reader reader;
reader.parse(js,root);
const Json::Value classes = root["results"][0]["result"]["tag"]["classes"];
相关文章:
- 为什么我不能将一个对象push_back到属于另一个类的对象向量中?
- 在他自己的方法中,有可能将一个对象取消引用到另一个对象吗
- 从多个源构造一个对象,包括一个对象向量
- 为什么C++在将一个对象复制到另一个对象时需要对这两个对象进行低级常量限定
- 检查哪个对象调用了另一个对象的对象方法
- C++ 如何在将新对象分配给另一个对象时创建新对象
- 如何处理从一个对象传递到另一个在C++中具有公共抽象类的对象的消息
- 我有一个对象,它将在整个程序的持续时间内实例化,但一个类成员不会,我应该动态分配它吗?
- 包装一个对象并假装它是一个 int
- 为什么我可以在不重载 "=" 运算符的情况下将一个对象分配给另一个对象?
- 如何在qt中将信号和插槽与另一个对象连接 --解决了
- 如何使用函数将一个对象的输入复制到另一个对象中
- 选择一个元素而不是一个对象的数组的原因
- 为什么我可以使用 memcpy 将一个对象变量复制到另一个对象变量
- 如何将包含另一个对象向量的对象保存到文件中,并使用C++中的二进制文件从文件中读回?
- 我重载了 << 和 = 运算符。为什么当我将一个对象分配给另一个对象并尝试打印它时,我会被打印出来?
- 打印对象的映射,其中另一个对象作为键
- 如何通过另一个对象中的命令正确地从一个对象返回数据
- 为什么将两个对象分配给另一个对象后,两个对象不一样?
- jsoncpp Json::LogicError,当我尝试解析一个对象时