JsonBlock¶
ShorthandGet¶
JsonData& ShorthandGet(const std::string shorthand, const char delimiter = '.')
JsonData& ShorthandGet(const std::string shorthand, const std::string delimiter)
const JsonData& ShorthandGet(const std::string shorthand, const char delimiter = '.') const
const JsonData& ShorthandGet(const std::string shorthand, const std::string delimiter) const
Shorthand function.
A shorthand function is designed to make working with deep, nested json structures easier and faster.
Does the same as Get(), but with a shorthand label.
If you, for whatever reason, don't want to use the '.'
delimiter, you can specify a custom one. It can even be a string!
Shorthand validity¶
If the shorthand is invalid, a JsonShorthandInvalidException will be thrown.
The validity of a shorthand depends on the function it is given to.
In this case, a shorthand is invalid, if
- The shorthand is empty (
""
) - At least one path segment does not exist
- At least one non-last path segment is not of type
JSON
Examples:¶
Json:¶
{
"id": {
"names": {
"firstname": "Joseph"
}
}
}
C++:¶
std::string fname = myJsonBlock.ShorthandGet("id.names.firstname").AsString;
Custom delimiter (C++):¶
std::string fname = myJsonBlock.ShorthandGet("id->names->firstname", "->").AsString;
std::string fname = myJsonBlock.ShorthandGet("id/names/firstname", '/').AsString;