假设我有一个 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/