C++ c++;已对rapidjson调用abort()

C++ c++;已对rapidjson调用abort(),c++,rapidjson,C++,Rapidjson,我正在做一些代码,我需要使用rapidjson来获取json值 首先,我从文件中检索信息 ifstream myReadFile; myReadFile.open("results.txt"); string output; if (myReadFile.is_open()) { while (!myReadFile.eof()) { myReadFile >> output; } }

我正在做一些代码,我需要使用rapidjson来获取json值

首先,我从文件中检索信息

   ifstream  myReadFile;
    myReadFile.open("results.txt");
    string output;
    if (myReadFile.is_open()) {
        while (!myReadFile.eof()) {
            myReadFile >> output;
        }
    }
    myReadFile.close();
results.txt的示例:

[{"ID":1,"Name":"SomeName","Description":"Pub"}]
然后我用rapidjson过滤信息

const char * json = output.c_str();
Document document;
document.Parse(json);
cout << document["ID"].GetInt();  //Error on the line
cout << document["Name"].GetString());
const char*json=output.c_str();
文件;
Parse(json);

cout您的json是一个数组,但您正在尝试解析它,因为它不是

从json字符串中删除方括号,然后您的代码就可以工作,或者解析数组:

for (SizeType i = 0; i<document.Size(); i++)
{
    const rapidjson::Value &data_vec = document[i];
    int id = data_vec["ID"].GetInt();
    std::string name = data_vec["Name"].GetString();
}

for(SizeType i=0;i在我看到那篇帖子后,我尝试了以下几行:“while(myReadFile>>output){”和“while(!(myReadFile>>std::ws.eof()){”,对于您的时间和解释,似乎都不起作用@melpomeneThanks,您的答案解决了我的问题,所以我接受正确的答案!)