Re: [Cppcms-users] Is there any way to get a list of key values from a JSON object?
Brought to you by:
artyom-beilis
From: kpeo <sla...@ya...> - 2012-05-10 18:05:17
|
<div>Hello,</div><div> </div><div>As explained in message before, use iterators over json object:</div><div> </div><div> cppcms::json::object ob=settings().get<cppcms::json::object>("imageservice.types");<br /><br /> for(cppcms::json::object::const_iterator p=ob.begin();p!=ob.end();++p) {<br /> if(p->second.type() == cppcms::json::is_object){<br /> std::cout << "key [" << p->first << "]: " << p->second << std::endl;<br /> } <br /> } </div><div> </div><div>Full code (for *nix) attached, compile: "g++ -lcppcms main.cpp -o test"</div><div> </div><div>Also, for some detail, see article:</div><div> </div><div>http://cppcms.com/wikipp/en/page/cppcms_1x_json</div><div> </div><div>10.05.2012, 20:58, "doug livesey" <bi...@gm...>:</div><blockquote type="cite">Hi -- if I had this json object:<div><div>{</div><div> "service": {</div><div> "api": "http",</div><div> "port": 3001</div><div> },</div><div> "http": {</div><div> "script_names": [ "/imageservice" ]</div><div> },</div><div> "imageservice": {</div><div> "secret": "sup3rs3cr3t",</div><div> "storage": "tmp",</div><div> "types": {</div><div> "test-type-1": {</div><div> "on_save": [ ".JPEG" ],</div><div> "versions": {</div><div> "big": [ "300x1000>" ],</div><div> "thumb": [ "75x75#" ],</div><div> "thumb-png": [ "75x75#", ".PNG" ]</div><div> }</div><div> },</div><div> "test-type-2": {</div><div> "on_save": [ "600x150!" ],</div><div> "versions": {</div><div> "gallery-jpeg": [ "50%", ".JPEG" ],</div><div> "gallery-png": [ "50%", ".PNG" ]</div><div> }</div><div> }</div><div> }</div><div> }</div><div>}</div></div><div>Would it be possible for me to query the JSON value object to find out that there are two "type" values in the "imageservice" bit, and that those types had keys of "test-type-1" and "test-type-2"?</div><div>I've been trying & failing to achieve this.</div><div>Thanks for any & all help,</div><div> Doug.</div><p>------------------------------------------------------------------------------<br />Live Security Virtual Conference<br />Exclusive live event will cover all the ways today's security and <br />threat landscape has changed and how IT managers can respond. Discussions <br />will include endpoint security, mobile security and the latest in malware <br />threats. <a href="http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/">http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/</a></p><p>_______________________________________________<br />Cppcms-users mailing list<br /><a href="mailto:Cpp...@li...">Cpp...@li...</a><br /><a href="https://lists.sourceforge.net/lists/listinfo/cppcms-users">https://lists.sourceforge.net/lists/listinfo/cppcms-users</a></p></blockquote> |