Condensed JSON creation code
I want to produce following JSON {"lib":100,"status":{"code":1000,"msg":"Success."}}
This is my code which works fine
Poco::JSON::Object RetJson(true); RetJson.set("lib", 100); Poco::JSON::Object JStatus(true); JStatus.set("code", 1000); JStatus.set("msg", "Success"); RetJson.set("status", JStatus);
In above code I do not like creation of JStatus object. Therefore I want to use reduced JSON creation if available like following. Poco::JSON::Object RetJson(true); RetJson.set("lib", 100); RetJson.get("status").set("code", 1000); //will not compile RetJson.get("status").set("msg", "Success"); //will not compile
RetJson.get("status")["code"]= 1000; //will throw exception RetJson.get("status")["msg"]= "Success"; //will throw exception
Please, let me know if you have alternatives.
A new method "addObject" which returns the newly object could help and the set method must be changed so that it returns the current object.
Poco::JSON::Object` RetJson(true);
RetJson.set("lib", 100);
RetJson.addObject("status")
.set("code", 1000)
.set("msg", "Success");
Is this what you are looking for?
Thanks your help. I decided to use another library for JSON.