作者smartjay (高毛毛)
看板C_and_CPP
标题[问题] 利用nlohmann json 读取crash
时间Mon Apr 9 14:46:50 2018
开发平台(Platform): (Ex: Win10, Linux, ...)
Win10
编译器(Ex: GCC, clang, VC++...)+目标环境(跟开发平台不同的话需列出)
VC2017
额外使用到的函数库(Library Used): (Ex: OpenGL, ...)
nlohmann/json
问题(Question):
欲利用josn 读取一个从cline接收到的字串,
可以依据其key 读取value ,
读取时发生错误
喂入的资料(Input):
client传送来的文字串
[
{
"_id": "5acb0a9494eb20cde1dbe689",
"index": 0,
"guid": "210941f6-9151-4315-8dfe-d7e0485afb18"
},
]
预期的正确结果(Expected Output):
auto keep = j_from_cbor["_id"] ; // keep = 5acb0a9494eb20cde1dbe689
错误结果(Wrong Output):
程式错误
程式码(Code):(请善用置底文网页, 记得排版,禁止使用图档)
https://ideone.com/vxFCgF
补充说明(Supplement):
加入第150行欲读取时发生错误。
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 60.248.167.253
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_and_CPP/M.1523256414.A.543.html
※ 编辑: smartjay (60.248.167.253), 04/09/2018 14:48:42
1F:→ lylu: 猜是最後右大括号後的逗点造成json parse error 04/09 16:57
2F:→ smartjay: 感谢1大提醒!用json complete = json::parse(folder); 04/09 17:47
3F:→ smartjay: 可以完整依key读value 04/09 17:47
4F:→ smartjay: parse 将字串(json)转为josn物件 进行 读取 04/09 17:48