【发布时间】:2021-03-03 19:14:35
【问题描述】:
我收到堆栈损坏提示“运行时检查失败 #2 - 变量 'root' 周围的堆栈已损坏。”使用以下代码:
#include <json/json.h>
#include <fstream>
#include <iostream>
#include <string>
int main() {
Json::Value root;
Json::Reader reader;
ifstream file("input.json");
if (!reader.parse(file, root)) {
cout << "Failed to parse configuration\n"
<< reader.getFormattedErrorMessages();
return 0;
}
file.close();
cout << root << endl;
return 0;
}
文件 input.json 包含:
[
{
"id": "id"
}
]
知道为什么会发生这种情况,我该如何调试?
提前致谢!!
【问题讨论】:
-
什么是 JSON。没有输入很难重现问题。
-
看起来您正在使用旧版本或使用已弃用的
Reader类。不能肯定,但您可能刚刚找到了它被从图书馆中移除的原因之一。 -
你试过ThorsSerializer吗?:gist.github.com/Loki-Astari/d0c0abd877dea82ee1af0c4114e92446