Typed view of a JSON object for checking keys and stepping through its members.
You obtain a JSONObject by calling JSON::AsObject() on a JSON value.
This function checks for a key and iterates over every member in an object:
void ConnectServers(
const JSON& prefs) {
if (!servers.
Has(
"default"))
Log("no default server");
Connect(member.key, member.value.Or(""));
}
JSONObject AsObject() const
Get a typed view of this value as an object (for iteration, Has(), and size()).
friend class JSON
Definition JSON.h:759
JSONObject(const JSONObject &other)
Copy constructor.
bool Has(const String &key) const
Whether or not the object has a member with the given key.
One object member, as visited by JSONObject iteration.
Definition JSON.h:423
Member Iteration
Iteration visits members in the order they were parsed or first added, and assigning to an existing key keeps its position.
Calling JSON::AsObject() on a missing key or a value that isn't an object produces an empty view, so the loop doesn't run.
- See also
- JSON::AsObject(), JSON::Member, JSONArray