我正在尝试打开一个 json 文件.并将其存储为 JSON 对象
I am trying to open a file that is a json. and store it as an json object.
我正在尝试打开一个具有json扩展名的文件并将其存储为对象。 但是,不断收到一条错误消息,指出文件名未在作用域中声明。 我是使用 json 文件的新手。 您对待它们的方式是否与普通文本文件不同?
#include "json.hpp"
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
int main(int argc, char** argv) {
std::ifstream file;
file.open(test.json);
nlohmann::json jsonObject;
// Store the contents filename into jsonObject
if (file.is_open()) {
file >> jsonObject;
}
file.close();
}
将test.json
作为文件名传递给open
-函数。因此,编译器假定名为 test
的对象具有数据成员 json
。除非在代码中定义了这样的对象,否则编译器会告诉您作用域中没有名为test
的对象。这就是原因。
你可能的意思是...
if (file.open("test.json")) {
...
相关文章:
- 如何使用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 并没有停止