0
    // Parse JSON and show errors if needed
Json::CharReaderBuilder rbuilder;Json::Reader reader;
Json::Value root;
// Configure the Builder, then ...
std::string errs;
std::istringstream config_doc(jsonString);

bool parsingSuccessful = Json::parseFromStream(rbuilder, config_doc, &root, &errs);

here we get Json::value root which gives us ordered list of the parameters how can we get the original state of params? jsonString example= { "_id" : 0, "title" : "", "author" : "", "available" : 0, "checkout" : "" }

with above example when we iterate the root i get : _id, author,available,checkout,title which is ordered by parameter name but i want it in the order the json object is i.e _id,title,author,available,checkout

any help?

2
  • What do you mean by "ordered" Json::value? What is the output you get and what do you expect? Can you please edit the post and clarify this? Commented Jan 19, 2022 at 6:55
  • 1
    jsoncpp simply doesn't support this, see e.g. here. the json specification also doesn't--a JSON object is an unordered collection of key-value pairs, so there's no obligation for a conforming parser to respect insertion order. if you need the order of elements to remain stable, consider using JSON arrays like [{"paramName": "_id":, "paramValue": "0"}, ... ] instead of objects Commented Jan 19, 2022 at 6:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.