当我try 使用nlohmann库在C++中解析文件时,我真的很困惑为什么会收到解析错误.
我的代码与我从他们的GitHub页面上复制的代码完全相同:
using json = nlohmann::json;
int main() {
ifstream ifs("test.json");
if (nlohmann::json::accept(ifs))
cout << "accepted" << endl;
else
cout << "not accepted" << endl;
json j = json::parse(ifs);
}
JSON文件就是这样的:
{
"test": 5
}
由于某些原因,当我到达parse()
函数时,这会抛出一个错误,尽管accept()
函数返回TRUE,这意味着JSON被接受为有效的.
另外,当我做这样的事情时:
json j = json::parse(R"({"test": "aaa"})");
这很好用.但我无法解析ifstream
对象.
有谁知道这里可能出了什么问题吗?
我没有 idea ,我也没有头绪,因为似乎我做的每件事都是对的.