断言 for rapidJson 失败了
assert is failing for rapidJson
我正在尝试使用RapidJson解析c ++中的json数据。我不知道我哪里做错了,但我的断言失败了。当我尝试调试它的显示 sigabrt 时,当它运行行断言时。社区 我感谢您的见解。感谢您回答这个幼稚的问题。
#include <iostream>
#include <assert.h>
#include "hpdf.h"
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include <rapidjson/istreamwrapper.h>
#include <fstream>
int main() {
std::ifstream ifs("/home/is/..../test.json");
rapidjson::IStreamWrapper isw(ifs);
rapidjson::Document document;
document.ParseStream(isw);
assert(document.IsObject());
rapidjson::Value::MemberIterator hello = document.FindMember("timeStamp");
std::string vali = document["timestamp"].GetString();
std::cout << vali << std::endl;
return 0;
}
我也尝试使用 rapidJson 文件流,但在同一行再次失败。
[
{
"timeStamp": "...",
"alertType": "...",
"instanceId": 8
}
]
阅读有关 JSON 的更多信息。
您的输入文档(以 [
开头)是一个包含单个 JSON 对象的 JSON 数组。
我建议使用 document.GetType()
然后对其结果进行不同的处理(可能带有 switch
)。
所以document.IsObject()
是假的很正常。对于您的输入document.IsArray()
应该是真的,并且该数组中的 JSON 对象可以通过 document[0]
<</p>
是错误的。
然而,"timeStamp"
并不等同于"timestamp"
伙计们,我想我已经解决了这个问题。你们从一开始就是对的。我的 data.json 有问题。当 .json 文件中没有 [] 时,此库有效。我删除了方括号,一切似乎都很好。感谢您的时间和见解。我感谢你们的所有答复。
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 从父数组测试用例构造二叉树失败
- LibGit2 SSH身份验证失败
- 如何让LLDB在成功时退出,在失败时等待
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 断言 'fp_ != 0' 失败 (RapidJSON)
- 断言 'IsArray()' 失败 (RapidJSON)
- 断言 for rapidJson 失败了