Simpleson
objectarray.cpp

This is an example of how to handle an array of JSON objects

#include "json.h"
#include <stdio.h>
#include <assert.h>
int main(void)
{
// Create a couple objects
json::jobject obj1 = json::jobject::parse("{\"hello\":\"world\"}");
obj2["key"] = "value";
// Put the objects in a vector
std::vector<json::jobject> vec;
vec.push_back(obj1);
vec.push_back(obj2);
// Create an object and add the array
json::jobject example;
example["array"] = vec;
// Print the result
printf("%s\n", example.pretty().c_str());
// Access each item
assert(example["array"].array(0) == obj1);
assert(example["array"].array(1) == obj2);
// Read back the entire array
std::vector<json::jobject> readbackarray = example["array"];
// Access each item
json::jobject readback1 = readbackarray[0];
assert(readback1 == obj1);
json::jobject readback2 = readbackarray[1];
assert(readback2 == obj2);
}
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
std::string pretty(unsigned int indent_level=0) const
Returns a pretty (multi-line indented) serialzed representation of the object or array.
Definition: json.cpp:997
Simpleson header file.