【问题标题】:Stack corruption with jsoncppjsoncpp 导致堆栈损坏
【发布时间】: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 类。不能肯定,但您可能刚刚找到了它被从图书馆中移除的原因之一。

标签: c++ jsoncpp


【解决方案1】:

jsoncpp 中的 Reader 类似乎已过时。参考https://github.com/open-source-parsers/jsoncpp/blob/master/example/readFromStream/readFromStream.cpp上的最新示例

【讨论】:

    猜你喜欢
    • 2014-08-13
    • 1970-01-01
    • 1970-01-01
    • 2012-11-23
    • 1970-01-01
    • 2016-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多