2014-05-13 35 views
0

我是Rapidjson的新手,無法找到我想要的。問題是這樣的,說我有一個JSON,它有一個錯誤,不能被解析。然後我想解析另一個json,它可以替換原來的json。但我想要使用相同的rapidjson::Documet來做到這一點,只要最終我需要在該文檔中解析有效的json。Rapidjson解析另一個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\" }"); 
} 

回答

2

是的,如果第一解析HES錯誤,則通過使用相同document是確定的,只要它清除數據解析另一個JSON並重新解析。