c++ - 如果第一个有错误,Rapidjson 会解析另一个 json

标签 c++ rapidjson

假设我有一个 JSON 字符串,它有一个错误,因此无法解析。然后我想解析另一个 JSON 字符串,它将替换原来的字符串。我想使用相同的 rapidjson::Document 来做到这一点,因为最终我需要在该文档中解析有效的 JSON。

所以:

rapidjson::Document document;
if (document.Parse<0>("{ \"hello\" : \"wor........ ").HasParseError())
{
    // How to parse the correct json "{ \"hello\" : \"world\" }" here
    // using the same `Document` ?
}

我应该写吗

if (document.Parse<0>("{ \"hello\" : \"wor........ ").HasParseError())
{
   document.Parse<0>("{ \"hello\" : \"world\" }"); 
}

最佳答案

是的,如果首先解析他的错误然后使用相同的文档解析另一个 JSON 是可以的,只要它清除该数据并重新解析。

关于c++ - 如果第一个有错误,Rapidjson 会解析另一个 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23634382/

相关文章:

c++ - parallel_for ppl.h 不比顺序 C++ 快

c++ - Rapidjson 迭代并获取复杂 JSON 对象成员的值

linux - 如何在没有 git 的情况下设置rapidjson

c++ - 损坏的输出,可能是由于失去了 rapidjson::Document::Allocator 的所有权

C++ rapidjson 返回值

c++ - 有没有办法为 C++ api 打包 Tensorflow?

C++ iostream 无法正常工作

c++ - 确保正确释放 C++ 对象

c++ - 如何从 QML 设置模型数据?

c++ - RapidJSON:如何只解析第一级?