SG++-Doxygen-Documentation
|
This example demonstrates how to use the basic functionality of SG++ JSON API.
The goal of this API is to facilitate generation and parsing of complex configuration files. Also it permits easy but limited object serialization functionality.
We first create an empty JSON object
Then we introduce the following JSON structure:
{ parent:{ "t1":"v1"; "t2":"v2"; "list1":["tv1",96.0,"tv2"] }; "textAttr1":"text1"; "numVal1":36.0 }
As you can see in the code below, methods to append new entries support chaining for convenience.
You can conveniently get and set values inside the JSON object using Key/Value notation.
This call gets the string representation of the second entry (96.0
) in list1
of dictionary parent
.
This call sets the second entry (96.0
) in list1
of dictionary parent
to the double value 7
and then prints its string representation.
You can also try to obtain a typed representation of an entry. Conversion is performed automatically and may result in an exception if it can't be converted.
Next we demonstrate erasing values.
Here we erase numVal1
from the top level of the configuration
object.
Now we erase the dictionary named parent
from the the configuration
object. Note that the object that is erased is returned to us by the erase operation. All Objects inside a JSON object are represented internally as an object of type Node
"
Serialization (i.e. writing of a standard compatible json file) is also possible.
We can also read a JSON file by passing it's path to the constructor of a JSON object