Menu

#30 Adding JSON objects iterator

Release 1.2
closed
nobody
None
1
2015-12-13
2015-11-30
CN Liou
No

The input JSON string may be like this:

{
"JOHN" : 15,
"MARY" : 25,
"ROCKY" : 35,
"STEVE" : 45
}

Method cppcms::json::value::at() is not quite useful because we do not know the keys in advance. An objects iterator can solve this problem if it is provided.

Discussion

  • CN Liou

    CN Liou - 2015-11-30

    Pardon my English!
    Edit my original wording to make it more polite (I think):

    "Method cppcms::json::value::at() is not quite useful if we do not know the keys in advance."

    If objects iterator is provided by cppcms::json::value, then we can iterate the objects and inspect each element. Furthermore, we can use the iterator to convert cppcms::json::object to cppcms::json::array.

     
  • Artyom Beilis

    Artyom Beilis - 2015-11-30

    Note:

    cppcms::json::object is std::map< string_key, value >
    cppcms:;json::array is std::vector< value >

    See: http://cppcms.com/cppcms_ref/latest/namespacecppcms_1_1json.html

    You can retreive object or to array from value by calling value::object and value::array member functions.

    And now you can iterate :-)

    If it is what you wanted I'll close the request, otherwise explain what else you want.

     
  • CN Liou

    CN Liou - 2015-11-30

    Indeed!
    I must have been sitting in front of my screen for too long and thus my brain starts to function poorly.

    Please go ahead and close it.

    Best Regards,

     
  • Artyom Beilis

    Artyom Beilis - 2015-12-13
    • status: open --> closed
    • Priority: 9 --> 1
     
  • Artyom Beilis

    Artyom Beilis - 2015-12-13

    Not a bug

     

Anonymous
Anonymous