docs
Loading...
Searching...
No Matches
JSONArray

#include <Ultralight/JSON.h>

Overview

A view of a JSON array.

Calling JSON::AsArray() on a JSON value returns a JSONArray view. You use it to step through array elements in a range-for loop and append new values.

This example appends values to an array and logs each element:

JSON scores = JSON::Array();
JSONArray entries = scores.AsArray();
entries.Push(1200);
entries.Push(950);
for (JSON score : entries)
Log(score.Stringify().utf8().data());
friend class JSON
Definition JSON.h:904
JSONArray(const JSONArray &other)
Copy constructor.
void Push(const JSON &value)
Append value, sharing its document.
JSONArray AsArray() const
Get a typed view of this value as an array (for iteration, size(), and Push()).
static JSON Array()
Create a new empty array value.

Elements and Appending

Iterating over the array yields each element as a JSON that shares the underlying document.

Calling JSON::AsArray() on a value that isn't an array returns an empty view. The loop doesn't run, and Push() does nothing.

See also
JSON::AsArray(), JSONObject

Classes

class  iterator
 Input iterator over an array's elements (yields JSON by value). More...

Public Member Functions

 JSONArray (const JSONArray &other)
 Copy constructor.
 ~JSONArray ()
 Destructor.
size_t size () const
 Get the number of elements (0 for an empty view).
void Push (const JSON &value)
 Append value, sharing its document.
void Push (bool value)
 Append a boolean.
void Push (double value)
 Append a number.
void Push (int value)
 Append a number.
void Push (unsigned value)
 Append a number.
void Push (long value)
 Append a number.
void Push (unsigned long value)
 Append a number.
void Push (long long value)
 Append a number.
void Push (unsigned long long value)
 Append a number.
void Push (const String &value)
 Append a string.
void Push (const char *value)
 Append a string.
void Push (decltype(nullptr))
 Append a JSON null.
iterator begin () const
 Get an iterator to the first element.
iterator end () const
 Get an iterator past the last element.

Friends

class JSON

Constructor & Destructor Documentation

◆ JSONArray()

JSONArray ( const JSONArray & other)

Copy constructor.

◆ ~JSONArray()

~JSONArray ( )

Destructor.

Member Function Documentation

◆ begin()

iterator begin ( ) const
inline

Get an iterator to the first element.

◆ end()

iterator end ( ) const
inline

Get an iterator past the last element.

◆ Push() [1/12]

void Push ( bool value)

Append a boolean.

◆ Push() [2/12]

void Push ( const char * value)

Append a string.

◆ Push() [3/12]

void Push ( const JSON & value)

Append value, sharing its document.

Note
An invalid value appends nothing.

◆ Push() [4/12]

void Push ( const String & value)

Append a string.

◆ Push() [5/12]

void Push ( decltype(nullptr) )

Append a JSON null.

◆ Push() [6/12]

void Push ( double value)

Append a number.

◆ Push() [7/12]

void Push ( int value)

Append a number.

◆ Push() [8/12]

void Push ( long long value)

Append a number.

◆ Push() [9/12]

void Push ( long value)

Append a number.

◆ Push() [10/12]

void Push ( unsigned long long value)

Append a number.

◆ Push() [11/12]

void Push ( unsigned long value)

Append a number.

◆ Push() [12/12]

void Push ( unsigned value)

Append a number.

◆ size()

size_t size ( ) const

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

◆ JSON

friend class JSON
friend

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