【问题标题】:Rapidjson parse another json if first one has errors如果第一个有错误,Rapidjson 会解析另一个 json
【发布时间】:2014-05-13 14:40:36
【问题描述】:

假设我有一个 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\" }"); 
}

【问题讨论】:

    标签: c++ rapidjson


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-26
      • 1970-01-01
      • 2012-10-14
      • 1970-01-01
      相关资源
      最近更新 更多