This is an example of how to handle JSON where the root object is an array
#include <stdio.h>
#include <assert.h>
int main(void)
{
const std::string test =
"["
" {"
" \"firstName\": \"Jimmy\","
" \"lastName\": \"D\","
" \"hobbies\": ["
" {"
" \"sport\": \"tennis\""
" },"
" {"
" \"music\": \"rock\""
" }"
" ]"
" },"
" {"
" \"firstName\": \"Sussi\","
" \"lastName\": \"Q\","
" \"hobbies\": ["
" {"
" \"sport\": \"volleyball\""
" },"
" {"
" \"music\": \"classical\""
" }"
" ]"
" }"
"]";
printf("Music desired: %s\n", music_desired.c_str());
assert(music_desired == std::string("rock"));
printf("Music desired: %s\n", music_desired.c_str());
assert(music_desired == std::string("classical"));
}
const_value array(const size_t index) const
Returns another constant value from this array.
Definition: json.h:826
const_value get(const std::string &key) const
Returns another constant value from this object.
Definition: json.h:814
std::string as_string() const
Returns a string representation of the value.
Definition: json.h:636
The class used for manipulating JSON objects and arrays.
Definition: json.h:410
static jobject parse(const char *input)
Parses a serialized JSON string.
Definition: json.cpp:887
const jobject::const_value array(const size_t index) const
Returns the value of an element in an array.
Definition: json.h:1066