DAW JSON Link
|
Parsing arrays is common and it is a fundamental data structure in JSON. It can be both the root object or a member.
The above JSON document contains an array of integers as the root object.
The C++ to parse this could look like
To see a working example of the following, refer to cookbook_array1_test.cpp The previous is a simple example, had the element type of the array been more complicated, such as a class, a data mapping would be required.
Here we hae a JSON array containing a class with members of type string, unsigned, float, and boolean.
The C++ data structures and the mapping could look like the following To see a working example using this code, refer to cookbook_array2_test.cpp
The above would construct MyClass4 with arguments of types std::string, unsigned, float, bool
Use the json_array
member type in the member list to describe a member that is an array type.
To see a working example using this code, refer to cookbook_array3_test.cpp
The above JSON document, has an object root, with int, array of int, and an array of string members
The C++ data structures could look like the following
The json_data_contract
specialization as follows
For dealing with pointer like arrays(T *, has element_type type alias) see int_ptr_test