JsonBlock¶
Set¶
JsonData& Set(const std::string label)
JsonData& Set(const JsonElement ele)
Basically just this:
if (DoesExist(label)) return Get(label);
else return Add(label);
or, if called with a JsonElement:
if (DoesExist(ele.GetLabel())) return Get(ele.GetLabel());
else return Add(ele);
See
Use this function if you want to put a value into a JsonBlock, no matter what.
If a value of this label already exists, it will be overwritten.
If it does not exist, it will be created.
Examples¶
Json held in this JsonBlock:¶
{
"name": "Angela Merkel",
"appearance": "Blue men shoes"
}
Will get values (C++):¶
// This is the explicit syntax.
// Can be written sleeker with the implicit syntax
std::string name = myJsonBlock.Set("name").AsString;
std::string appe = myJsonBlock.Set("appearance").AsString;
Will add / overwrite values (C++):¶
// This is the explicit syntax.
// Can be written sleeker with the implicit syntax
std::string name = myJsonBlock.Set("name").SetStringValue("Angela Morkel");
std::string appe = myJsonBlock.Set("age").SetIntValue(66);
Aliases¶
Alternative ways to call this function
myJsonBlock["age"] = 66
myJsonData["age"] = 66
Also works on this JsonBlocks JsonData object! (Exception if not of typeJSON
)