JsonBlock¶
Add¶
JsonData& Add(const std::string label)
JsonData& Add(const JsonElement ele)
If called with a "std::string label"¶
Will create a new JsonElement with the label label
and return a reference to it's JsonData.
Will throw a JsonLabelAlreadyExistsException, if that label already exist.
You can check that with DoesExist()
.
If called with a JsonElement¶
Will append a copy of the supplied JsonElement and return a reference to it's JsonData.
Will throw a JsonLabelAlreadyExistsException, if its label already exist.
You can check that with DoesExist()
.
Examples¶
We'll start with a JsonBlock holding this json:¶
{
"name": "Angela Merkel",
"appearance": "Blue men shoes"
}
Now add some more values (C++):¶
// This is the explicit syntax.
// Can be written sleeker with the implicit syntax
myJsonBlock.Add("title").SetStringValue("Dr.")
myJsonBlock.Add("date-of-birth").SetStringValue("17.07.1954")
myJsonBlock.Add("date-of-birth-timestamp").SetIntValue(-487900800)
// This would be the sleek version:
myOtherJsonBlock += Ele("title", "Dr.");
myOtherJsonBlock += Ele("date-of-birth", "17.07.1954");
myOtherJsonBlock += Ele("date-of-birth-timestamp", -487900800);
And now our json looks like this¶
{
"name": "Angela Merkel",
"appearance": "Blue men shoes",
"title": "Dr.",
"date-of-birth": "17.07.1954",
"date-of-birth-timestamp": -487900800
}
Let's raise an exception to end with (C++):¶
myJsonBlock.Add("age").SetIntValue(66);
// JsonLabelAlreadyExistsException
myJsonBlock.Add("age").SetIntValue(66);
Aliases¶
Alternative ways to call this function
myJsonBlock += "age"
Will create a field called "age" with a nullvalue.myJsonBlock +=
Ele
("age", 66)
Will create a field called "age" with an int value of 66.myJsonData +=
Ele
("age", 66)
This also works on the JsonData object!! (Exception if not of typeJSON
).(myJsonBlock += "age") = 66
This technically works, but... really?.