docs
Loading...
Searching...
No Matches
JSONObject

#include <Ultralight/JSON.h>

Overview

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) {
JSONObject servers = prefs["servers"].AsObject();
if (!servers.Has("default"))
Log("no default server");
for (JSON::Member member : servers)
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

Classes

class  iterator
 Input iterator over an object's members (yields JSON::Member by value). More...

Public Member Functions

 JSONObject (const JSONObject &other)
 Copy constructor.
 ~JSONObject ()
 Destructor.
size_t size () const
 Get the number of members (0 for an empty view).
bool Has (const String &key) const
 Whether or not the object has a member with the given key.
iterator begin () const
 Get an iterator to the first member (insertion order).
iterator end () const
 Get an iterator past the last member.

Friends

class JSON

Constructor & Destructor Documentation

◆ JSONObject()

JSONObject ( const JSONObject & other)

Copy constructor.

◆ ~JSONObject()

~JSONObject ( )

Destructor.

Member Function Documentation

◆ begin()

iterator begin ( ) const
inline

Get an iterator to the first member (insertion order).

◆ end()

iterator end ( ) const
inline

Get an iterator past the last member.

◆ Has()

bool Has ( const String & key) const

Whether or not the object has a member with the given key.

◆ size()

size_t size ( ) const

Get the number of members (0 for an empty view).

◆ JSON

friend class JSON
friend

The documentation for this class was generated from the following file: