Re: [Cppcms-users] CppCMS 1.x.x JSON object value empty/not exist
Brought to you by:
artyom-beilis
|
From: Artyom <art...@ya...> - 2010-06-15 14:41:05
|
Yes you can.
Simplest way is to use get with default parameter. For example
json::value v;
v.get("foo.bar",10);
And if foo.bar is not defined or invalid you get 10 instead.
You can also use find member function and test the type:
if(v.find("foo.bar").type()==cppcms::json::is_number)
...
else
..
Take a look on documentation of: cppcms::json::value
http://art-blog.no-ip.info/cppcms_ref_v0_99_1/classcppcms_1_1json_1_1value.html
or (mirror)
http://cppcms.sourceforge.net/cppcms_ref_v0_99_1/classcppcms_1_1json_1_1value.html
Especially functions: find(), at(), get() they allow you to browse the object on different paths.
Regards,
Artyom
________________________________
From: Geert Van de Velde <gee...@ba...>
To: cpp...@li...
Sent: Tue, June 15, 2010 4:54:38 PM
Subject: [Cppcms-users] CppCMS 1.x.x JSON object value empty/not exist
Hi,
I'm trying to use cppcms for a new project and use it for building a
RESTLike API for a device. The API will communicate with the JSON data
format.
When receiving JSON data from a client some fields of an object are
optional. I'm using json::value for handling this.
I use the get<T> function to fetch the fields but in case of a missing
field or invalid field data it throws an exception. Is it possible to
detect that the field is missing separately? So I can ignore missing
optional fields.
Tnx
DISCLAIMER:
Unless indicated otherwise, the information contained in this message is privileged and confidential, and is intended only for the use of the addressee(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this message and/or attachments is strictly prohibited. The company accepts no liability for any damage caused by any virus transmitted by this email. Furthermore, the company does not warrant a proper and complete transmission of this information, nor does it accept liability for any delays. If you have received this message in error, please contact the sender and delete the message. Thank you.
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Cppcms-users mailing list
Cpp...@li...
https://lists.sourceforge.net/lists/listinfo/cppcms-users
|