Nlohmann JSON从文件中阅读
nlohmann json reading from file
我目前以这种方式在文件中阅读:
using json = nlohmann::json;
std::ifstream jsonConfigFileStream("/path/to/file.json", std::ifstream::in);
json jsonConfigRoot;
if (jsonConfigFileStream.is_open()) {
jsonConfigFileStream >> jsonConfigRoot;
}
但是,它一直给我带来错误
libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument
Abort trap: 6
错误应来自代码jsonConfigFileStream >> jsonConfigRoot
有人可以启发我发生的事情吗?
JSON文件中可能存在错误。在某些衬里中检查正确性。nlohmann json parser也不喜欢悬挂的分离器,例如
{"node":[1,2,3,4,]}
^
其他失败案例 - 除了数字以外的任何其他内容。
将其包裹在try...catch
和对数运行时错误中 - 在大多数情况下,它确实解释了为什么解析失败
如果此条件良好,则可以完全读取文件。将内容记录到stdout或sticka。
相关文章:
- 如何使用curlpp通过POST方法上传文件和json数据
- 如何在特定位置追加 json 文件
- 将 FlatBuffer 对象序列化为 JSON,而不使用其架构文件
- 如何在Visual C+++中从JSON文件中读取节点数据
- 如何将 json 数据附加到 Qt 中的现有 json 文件中
- 当前步骤:构建任务.json 文件
- 可以在JSON文件的帮助下在Qt中创建UI表单
- 将 cpprestsdk json 值对象写入文件
- 如何在 C++ 中使用提升属性树从 JSON 文件中读取对象数组
- 有没有办法从Makefile访问VS Code c_cpp_properties.json文件中的定义
- 保存json文件后如何返回文件路径
- 构造一个类似于JSON文件c++的字符串
- 使用 jsoncpp 读取 JSON 文件
- 在C++中打开 json 文件时遇到问题
- 使用 JSONCPP 将 JSON 数据增量写入文件
- Nlohmann 在不知道密钥的情况下解析 JSON 文件
- 如何使用 rapidjson 读取 json 文件并输出到 std::string?
- 比较 JSON::Value 变量中的数据,然后更新到文件
- 如何使用QJSONARRAY在QT5(C )中解析JSON文件(数组)
- 在 c++ 中读取配置文件 json 并没有停止