Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ JSON C++;解析时出现分段错误_C++_Json_Parsing - Fatal编程技术网

C++ JSON C++;解析时出现分段错误

C++ JSON C++;解析时出现分段错误,c++,json,parsing,C++,Json,Parsing,我想使用jsoncpp解析文件中的JSON键和值,代码与中类似 我的代码: Json::Value root; Json::阅读器; ifstream测试(“example2.json”,ifstream::binary); bool success=reader.parse(test,root,false); 如果(!成功){ 找不到coutexample2.json?不,这是奇怪的部分。它确实打印id(代码的最后一行),然后带分段错误退出。@spiralstatic 1)string id

我想使用jsoncpp解析文件中的JSON键和值,代码与中类似

我的代码:

Json::Value root;
Json::阅读器;
ifstream测试(“example2.json”,ifstream::binary);
bool success=reader.parse(test,root,false);
如果(!成功){

找不到coutexample2.json?不,这是奇怪的部分。它确实打印id(代码的最后一行),然后带分段错误退出。@spiralstatic 1)
string id=root[id]
我们不知道
id
是什么。2)即使
success
可能为false,您的代码也会继续执行这一行。很抱歉,我忘了添加“”当简化我的原始代码时。Id是一个字符串,是文件example2中的一个json键。你的第二句话也是对的,但这并不是错的地方。分段错误似乎来自reader.parse语句,但我不明白为什么,因为我几乎完全复制了我提到的教程中的代码。你自相矛盾。您说代码正在输出id,这只能在
parse()
没有崩溃的情况下发生。但您也说segfault发生在
parse()
中。您不能同时使用这两种方法。除非
parse())
正在内部吞咽segfault,而您看到它发生的唯一方式是因为您在调试器中运行。如果是这样,则忽略它。segfault实际上说什么?如果segfault在输出之后,则它不在
parse()中
。听起来更像是
Json::Value
Json::Reader
析构函数。