我正在使用nlohmann json,可以在这里找到
https://github.com/nlohmann/json#integration
我正在尝试从文件中读取json数据,这里是dictLoad1.json文件的一部分
编辑:所以我发现即使文件名正在生成正确的字符串,nlogmann的文件也没有打开。如果有人知道如何打开文件,我可以使用帮助。如果我搞清楚,我会更新。
"dictionary": [
{"word": "MEAGRE", "definition": "A large European scinoid fish (Scina umbra or S. aquila),having white bloodless flesh. It is valued as a food fish. [Writtenalso maigre.]"},
{"word": "GRUGRU WORM", "definition": "The larva or grub of a large South American beetle (Calandrapalmarum), which lives in the pith of palm trees and sugar cane. Itis eaten by the natives, and esteemed a delicacy."},
{"word": "POSTPONEMENT", "definition": "The act of postponing; a deferring
从那个github网站上可以看出如何从json文件中读取输入并将其存储到json变量中 -
// read a JSON file
std::ifstream i("file.json");
json j;
i >> j;
这是我的代码试图在json文件中读取
string filename = line.substr(input.size()+8, line.size());
filename[4] = toupper(filename[4]);
cout << filename << "\n"; //printing dictLoad1.json
std::ifstream i(filename);
json j;
i >> j;
代码在第i行&gt;&gt;处断开j
对于文件顶部的nlohmann我有
#include "json.hpp"
using json = nlohmann::json;
确切的错误是
[json.exception.parse_error.101] parse error at 1: syntax error - unexpected end of input; expected '[', '{', or a literal
Makefile:36: recipe for target 'test' failed