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: doug l. <bi...@gm...> - 2012-05-10 18:49:20
|
That did the trick, thankyou very much!
On 10 May 2012 19:05, kpeo <sla...@ya...> wrote:
> Hello,
>
> As explained in message before, use iterators over json object:
>
> cppcms::json::object
> ob=settings().get<cppcms::json::object>("imageservice.types");
>
> for(cppcms::json::object::const_iterator
> p=ob.begin();p!=ob.end();++p) {
> if(p->second.type() == cppcms::json::is_object){
> std::cout << "key [" << p->first << "]: " <<
> p->second << std::endl;
> }
> }
>
> Full code (for *nix) attached, compile: "g++ -lcppcms main.cpp -o test"
>
> Also, for some detail, see article:
>
> http://cppcms.com/wikipp/en/page/cppcms_1x_json
>
> 10.05.2012, 20:58, "doug livesey" <bi...@gm...>:
>
> Hi -- if I had this json object:
> {
> "service": {
> "api": "http",
> "port": 3001
> },
> "http": {
> "script_names": [ "/imageservice" ]
> },
> "imageservice": {
> "secret": "sup3rs3cr3t",
> "storage": "tmp",
> "types": {
> "test-type-1": {
> "on_save": [ ".JPEG" ],
> "versions": {
> "big": [ "300x1000>" ],
> "thumb": [ "75x75#" ],
> "thumb-png": [ "75x75#", ".PNG" ]
> }
> },
> "test-type-2": {
> "on_save": [ "600x150!" ],
> "versions": {
> "gallery-jpeg": [ "50%", ".JPEG" ],
> "gallery-png": [ "50%", ".PNG" ]
> }
> }
> }
> }
> }
> 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"?
> I've been trying & failing to achieve this.
> Thanks for any & all help,
> Doug.
>
>
> ------------------------------------------------------------------------------
>
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>
> _______________________________________________
> Cppcms-users mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppcms-users
>
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Cppcms-users mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppcms-users
>
>
|