C++ libcurl+错误;用于JSON解析的rapidjson(空dom) 我无法使用rapidjson的API(通过curl的帖子)将字符串解析为json

C++ libcurl+错误;用于JSON解析的rapidjson(空dom) 我无法使用rapidjson的API(通过curl的帖子)将字符串解析为json,c++,libcurl,rapidjson,C++,Libcurl,Rapidjson,如图所示,我已经得到了json,但我无法解析它来分析信息,因为Dom有空数据。作为初学者,我真的需要帮助,3Q~。 int main(int argc,const char*argv[]{ //在这里插入代码。。。 rapidjson::文档文档; doc.SetObject();//键值相当与地图 //doc.Setvalue()//数组型 相当与矢量 rapidjson::Document::AllocatorType&allocator=doc.GetAllocator()//获取分配器


如图所示,我已经得到了json,但我无法解析它来分析信息,因为Dom有空数据。作为初学者,我真的需要帮助,3Q~。
int main(int argc,const char*argv[]{
//在这里插入代码。。。
rapidjson::文档文档;
doc.SetObject();//键值相当与地图
//doc.Setvalue()//数组型 相当与矢量
rapidjson::Document::AllocatorType&allocator=doc.GetAllocator()//获取分配器
文件AddMember(“answerId”,“1804201043079617296361988”,分配器);
doc.AddMember(“queryItems”,true,分配器);
rapidjson::StringBuffer缓冲区;
rapidjson::PrettyWriter写入程序(缓冲区);//PrettyWriter是格式化的json如果是作家则是换行空格压缩后的json
//rapidjson::Writer-Writer(缓冲区);
//接受文件(作者);

//std::coutit断言我是“ParseError”,你应该在你的问题中显示完整的错误信息。“ParseError”不是很多信息。你在代码中从哪里得到错误?@super
document.Parse(strTemp.c_str());
@super你可以在我注释为“NULL DOM”的图片中看到数据,它没有任何数据。但是strTemp
已经保存了正确的数据。所以我不知道是怎么发生的。json是“@super”,谢谢你的重播。我写了一个func来查找错误。它告诉我“字符串中的转义字符无效”。
    int main(int argc, const char * argv[]) {
// insert code here...

rapidjson::Document doc;
doc.SetObject();    //key-value 相当与map
//doc.Setvalue();        //数组型 相当与vector
rapidjson::Document::AllocatorType &allocator = doc.GetAllocator(); //获取分配器

doc.AddMember("answerId","1804201043079617296361988",allocator);
doc.AddMember("queryItems", true, allocator);
rapidjson::StringBuffer buffer;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);  //PrettyWriter是格式化的json,如果是Writer则是换行空格压缩后的json
//rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
//doc.Accept(writer);
//std::cout<<buffer.GetString()<<std::endl;

    CURL *curl;
    CURLcode res;
    std::stringstream out;

    //HTTP报文头
    struct curl_slist* headers = NULL;

    const char *url = "https://www.qingsuyun.com/h5/actions/exam/execute/find-exam.json";

    curl = curl_easy_init();

    if(curl)
    {
        //设置url
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
        curl_easy_setopt(curl,  CURLOPT_CUSTOMREQUEST, "POST");//自定义请求方式

        // 设置要POST的params
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS,"answerId=1804201043079617296361988&queryItems=true");

        // 设置接收数据的处理函数和存放变量
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);//设置回调函数
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &out);//设置写数据
        res = curl_easy_perform(curl);//执行

        curl_slist_free_all(headers); /* free the list again */
        string str_json = out.str();//返回请求值
        printf("%s",str_json.c_str());

        int iStart = str_json.find("{");
        int iEnd = str_json.rfind("}");
        if ((iStart < 0) || (iEnd < 1) || (iStart > iEnd))
        {
            return -1;
        }
        std::string strTemp = str_json.substr(iStart, (iEnd - iStart + 1));
        rapidjson::Document document;

        document.Parse(strTemp.c_str());
        if (document.HasParseError())
        {
            return -1;
        }
        rapidjson::Document::AllocatorType& allocator = document.GetAllocator();}
     return 0;}