Faster JsonCpp alternative that allows copying/mutability of Json objects?

前端 未结 1 768
囚心锁ツ
囚心锁ツ 2021-01-15 01:03

JsonCpp is slow. And the code is pretty messy.

Is there any alternative that is faster, cleaner and supports stuff like:

Json::Value val, copy;
val[\         


        
相关标签:
1条回答
  • 2021-01-15 01:15

    After searching for some time the "documentation" I finally found a good way to copy JSON objects with rapidjson wich is very convenient:

    rapidjson::Document doc; // This is the base document that you got from parsing etc
    rapidjson::Value& v = doc["newMember"]; // newMember = 100
    
    assert(v.GetInt() == 100);
    
    rapidjson::Document copy;
    doc.Accept(copy); // The accept meachnism is the same as used in parsing, but for copying
    
    assert(copy["newMember"].GetInt() == doc["newMember"].GetInt())
    

    The explicit copying has one advantage: It forces you to think clearly about when you are using references or potentially unnecessary copies.

    0 讨论(0)
提交回复
热议问题