QtBase  v6.3.1
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
QJsonArray Class Reference

The QJsonArray class encapsulates a JSON array. More...

#include <qjsonarray.h>

Classes

class  const_iterator
 The QJsonArray::const_iterator class provides an STL-style const iterator for QJsonArray. More...
 
class  iterator
 The QJsonArray::iterator class provides an STL-style non-const iterator for QJsonArray. More...
 

Public Types

typedef iterator Iterator
 
typedef const_iterator ConstIterator
 
typedef qsizetype size_type
 
typedef QJsonValue value_type
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 
typedef QJsonValueRef reference
 
typedef QJsonValue const_reference
 
typedef qsizetype difference_type
 

Public Member Functions

 QJsonArray ()
 
 QJsonArray (std::initializer_list< QJsonValue > args)
 
 ~QJsonArray ()
 
 QJsonArray (const QJsonArray &other)
 
QJsonArrayoperator= (const QJsonArray &other)
 
 QJsonArray (QJsonArray &&other) noexcept
 
QJsonArrayoperator= (QJsonArray &&other) noexcept
 
QVariantList toVariantList () const
 
qsizetype size () const
 
qsizetype count () const
 
bool isEmpty () const
 
QJsonValue at (qsizetype i) const
 
QJsonValue first () const
 
QJsonValue last () const
 
void prepend (const QJsonValue &value)
 
void append (const QJsonValue &value)
 
void removeAt (qsizetype i)
 
QJsonValue takeAt (qsizetype i)
 
void removeFirst ()
 
void removeLast ()
 
void insert (qsizetype i, const QJsonValue &value)
 
void replace (qsizetype i, const QJsonValue &value)
 
bool contains (const QJsonValue &element) const
 
QJsonValueRef operator[] (qsizetype i)
 
QJsonValue operator[] (qsizetype i) const
 
bool operator== (const QJsonArray &other) const
 
bool operator!= (const QJsonArray &other) const
 
void swap (QJsonArray &other) noexcept
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator constBegin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator constEnd () const
 
const_iterator cend () const
 
iterator insert (iterator before, const QJsonValue &value)
 
iterator erase (iterator it)
 
QJsonArray operator+ (const QJsonValue &v) const
 
QJsonArrayoperator+= (const QJsonValue &v)
 
QJsonArrayoperator<< (const QJsonValue &v)
 
void push_back (const QJsonValue &t)
 
void push_front (const QJsonValue &t)
 
void pop_front ()
 
void pop_back ()
 
bool empty () const
 

Static Public Member Functions

static QJsonArray fromStringList (const QStringList &list)
 
static QJsonArray fromVariantList (const QVariantList &list)
 

Friends

class iterator
 
class const_iterator
 
class QJsonValue
 
class QJsonDocument
 
class QCborArray
 
Q_CORE_EXPORT QDebug operator<< (QDebug, const QJsonArray &)
 

Detailed Description

The QJsonArray class encapsulates a JSON array.

\inmodule QtCore

\reentrant

Since
5.0

A JSON array is a list of values. The list can be manipulated by inserting and removing QJsonValue's from the array.

A QJsonArray can be converted to and from a QVariantList. You can query the number of entries with size(), insert(), and removeAt() entries from it and iterate over its content using the standard C++ iterator pattern.

QJsonArray is an implicitly shared class and shares the data with the document it has been created from as long as it is not being modified.

You can convert the array to and from text based JSON through QJsonDocument.

See also
{JSON Support in Qt}, {JSON Save Game Example}

Definition at line 53 of file qjsonarray.h.

Member Typedef Documentation

◆ const_pointer

Typedef for const QJsonValue *. Provided for STL compatibility.

Definition at line 257 of file qjsonarray.h.

◆ const_reference

Typedef for const QJsonValue &. Provided for STL compatibility.

Definition at line 259 of file qjsonarray.h.

◆ ConstIterator

Qt-style synonym for QJsonArray::const_iterator.

Definition at line 238 of file qjsonarray.h.

◆ difference_type

Typedef for qsizetype. Provided for STL compatibility.

Definition at line 260 of file qjsonarray.h.

◆ Iterator

Qt-style synonym for QJsonArray::iterator.

Definition at line 237 of file qjsonarray.h.

◆ pointer

Typedef for QJsonValue *. Provided for STL compatibility.

Definition at line 256 of file qjsonarray.h.

◆ reference

Typedef for QJsonValue &. Provided for STL compatibility.

Definition at line 258 of file qjsonarray.h.

◆ size_type

Typedef for qsizetype. Provided for STL compatibility.

Definition at line 254 of file qjsonarray.h.

◆ value_type

Typedef for QJsonValue. Provided for STL compatibility.

Definition at line 255 of file qjsonarray.h.

Constructor & Destructor Documentation

◆ QJsonArray() [1/4]

QJsonArray::QJsonArray ( )
default

Creates an empty array.

◆ QJsonArray() [2/4]

QJsonArray::QJsonArray ( std::initializer_list< QJsonValue args)
Since
5.4 Creates an array initialized from args initialization list.

QJsonArray can be constructed in a way similar to JSON notation, for example:

QJsonArray array = { 1, 2.2, QString() };
The QJsonArray class encapsulates a JSON array.
Definition: qjsonarray.h:54
#define QString()
Definition: parse-defines.h:51
GLenum array
Definition: qopenglext.h:7028

Definition at line 166 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ ~QJsonArray()

QJsonArray::~QJsonArray ( )
default

Deletes the array.

◆ QJsonArray() [3/4]

QJsonArray::QJsonArray ( const QJsonArray other)

Creates a copy of other.

Since QJsonArray is implicitly shared, the copy is shallow as long as the object doesn't get modified.

Definition at line 178 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ QJsonArray() [4/4]

QJsonArray::QJsonArray ( QJsonArray &&  other)
noexcept
Since
5.10

Move-constructs a QJsonArray from other.

Definition at line 183 of file qjsonarray.cpp.

Here is the call graph for this function:

Member Function Documentation

◆ append()

void QJsonArray::append ( const QJsonValue value)

Inserts value at the end of the array.

See also
prepend(), insert()

Definition at line 366 of file qjsonarray.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ at()

QJsonValue QJsonArray::at ( qsizetype  i) const

Returns a QJsonValue representing the value for index i.

The returned QJsonValue is Undefined, if i is out of bounds.

Definition at line 317 of file qjsonarray.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ begin() [1/2]

QJsonArray::iterator QJsonArray::begin ( )
inline

Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array.

See also
constBegin(), end()

Definition at line 223 of file qjsonarray.h.

◆ begin() [2/2]

QJsonArray::const_iterator QJsonArray::begin ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 224 of file qjsonarray.h.

◆ cbegin()

QJsonArray::const_iterator QJsonArray::cbegin ( ) const
inline

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array.

See also
begin(), cend()

Definition at line 226 of file qjsonarray.h.

◆ cend()

QJsonArray::const_iterator QJsonArray::cend ( ) const
inline

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array.

See also
cbegin(), end()

Definition at line 230 of file qjsonarray.h.

◆ constBegin()

QJsonArray::const_iterator QJsonArray::constBegin ( ) const
inline

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array.

See also
begin(), constEnd()

Definition at line 225 of file qjsonarray.h.

Here is the caller graph for this function:

◆ constEnd()

QJsonArray::const_iterator QJsonArray::constEnd ( ) const
inline

Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array.

See also
constBegin(), end()

Definition at line 229 of file qjsonarray.h.

Here is the caller graph for this function:

◆ contains()

bool QJsonArray::contains ( const QJsonValue value) const

Returns true if the array contains an occurrence of value, otherwise false.

See also
count()

Definition at line 479 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ count()

QJsonArray::count ( ) const
inline

Same as size().

See also
size()

Definition at line 78 of file qjsonarray.h.

◆ empty()

bool QJsonArray::empty ( ) const
inline

This function is provided for STL compatibility. It is equivalent to isEmpty() and returns true if the array is empty.

Definition at line 253 of file qjsonarray.h.

◆ end() [1/2]

QJsonArray::iterator QJsonArray::end ( )
inline

Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array.

See also
begin(), constEnd()

Definition at line 227 of file qjsonarray.h.

◆ end() [2/2]

const_iterator QJsonArray::end ( ) const
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 228 of file qjsonarray.h.

◆ erase()

QJsonArray::iterator QJsonArray::erase ( iterator  it)
inline

Removes the item pointed to by it, and returns an iterator pointing to the next item.

See also
removeAt()

Definition at line 233 of file qjsonarray.h.

◆ first()

QJsonValue QJsonArray::first ( ) const

Returns the first value stored in the array.

Same as at(0).

See also
at()

Definition at line 332 of file qjsonarray.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromStringList()

QJsonArray QJsonArray::fromStringList ( const QStringList list)
static

Converts the string list list to a QJsonArray.

The values in list will be converted to JSON values.

See also
toVariantList(), QJsonValue::fromVariant()

Definition at line 251 of file qjsonarray.cpp.

◆ fromVariantList()

QJsonArray QJsonArray::fromVariantList ( const QVariantList list)
static

Converts the variant list list to a QJsonArray.

The QVariant values in list will be converted to JSON values.

Note
Conversion from \l QVariant is not completely lossless. Please see the documentation in QJsonValue::fromVariant() for more information.
See also
toVariantList(), QJsonValue::fromVariant()

Definition at line 269 of file qjsonarray.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [1/2]

QJsonArray::iterator QJsonArray::insert ( iterator  before,
const QJsonValue value 
)
inline

Inserts value before the position pointed to by before, and returns an iterator pointing to the newly inserted item.

See also
erase(), insert()

Definition at line 231 of file qjsonarray.h.

Here is the call graph for this function:

◆ insert() [2/2]

void QJsonArray::insert ( qsizetype  i,
const QJsonValue value 
)

Inserts value at index position i in the array. If i is 0, the value is prepended to the array. If i is size(), the value is appended to the array.

See also
append(), prepend(), replace(), removeAt()

Definition at line 431 of file qjsonarray.cpp.

Here is the caller graph for this function:

◆ isEmpty()

bool QJsonArray::isEmpty ( ) const

Returns true if the object is empty. This is the same as size() == 0.

See also
size()

Definition at line 306 of file qjsonarray.cpp.

Here is the caller graph for this function:

◆ last()

QJsonValue QJsonArray::last ( ) const

Returns the last value stored in the array.

Same as {at(size() - 1)}.

See also
at()

Definition at line 344 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ operator!=()

bool QJsonArray::operator!= ( const QJsonArray other) const

Returns true if this array is not equal to other.

Definition at line 542 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ operator+()

QJsonArray QJsonArray::operator+ ( const QJsonValue value) const
inline

Returns an array that contains all the items in this array followed by the provided value.

Since
5.3
See also
operator+=()

Definition at line 241 of file qjsonarray.h.

◆ operator+=()

QJsonArray & QJsonArray::operator+= ( const QJsonValue value)
inline

Appends value to the array, and returns a reference to the array itself.

Since
5.3
See also
append(), operator<<()

Definition at line 243 of file qjsonarray.h.

Here is the call graph for this function:

◆ operator<<()

QJsonArray & QJsonArray::operator<< ( const QJsonValue value)
inline

Appends value to the array, and returns a reference to the array itself.

Since
5.3
See also
operator+=(), append()

Definition at line 245 of file qjsonarray.h.

Here is the call graph for this function:

◆ operator=() [1/2]

QJsonArray & QJsonArray::operator= ( const QJsonArray other)

Assigns other to this array.

Definition at line 192 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ operator=() [2/2]

QJsonArray & QJsonArray::operator= ( QJsonArray &&  other)
inlinenoexcept
Since
5.10

Move-assigns other to this array.

Definition at line 67 of file qjsonarray.h.

Here is the call graph for this function:

◆ operator==()

bool QJsonArray::operator== ( const QJsonArray other) const

Returns true if this array is equal to other.

Definition at line 520 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ operator[]() [1/2]

QJsonValueRef QJsonArray::operator[] ( qsizetype  i)

Returns the value at index position i as a modifiable reference. i must be a valid index position in the array (i.e., {0 <= i < size()}).

The return value is of type QJsonValueRef, a helper class for QJsonArray and QJsonObject. When you get an object of type QJsonValueRef, you can use it as if it were a reference to a QJsonValue. If you assign to it, the assignment will apply to the character in the QJsonArray of QJsonObject from which you got the reference.

See also
at()

Definition at line 501 of file qjsonarray.cpp.

◆ operator[]() [2/2]

QJsonValue QJsonArray::operator[] ( qsizetype  i) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Same as at().

Definition at line 512 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ pop_back()

void QJsonArray::pop_back ( )
inline

This function is provided for STL compatibility. It is equivalent to removeLast(). The array must not be empty. If the array can be empty, call isEmpty() before calling this function.

Definition at line 252 of file qjsonarray.h.

◆ pop_front()

void QJsonArray::pop_front ( )
inline

This function is provided for STL compatibility. It is equivalent to removeFirst(). The array must not be empty. If the array can be empty, call isEmpty() before calling this function.

Definition at line 251 of file qjsonarray.h.

◆ prepend()

void QJsonArray::prepend ( const QJsonValue value)

Inserts value at the beginning of the array.

This is the same as {insert(0, value)} and will prepend value to the array.

See also
append(), insert()

Definition at line 356 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ push_back()

void QJsonArray::push_back ( const QJsonValue value)
inline

This function is provided for STL compatibility. It is equivalent to \l{QJsonArray::append()}{append(value)} and will append value to the array.

Definition at line 249 of file qjsonarray.h.

Here is the call graph for this function:

◆ push_front()

void QJsonArray::push_front ( const QJsonValue value)
inline

This function is provided for STL compatibility. It is equivalent to \l{QJsonArray::prepend()}{prepend(value)} and will prepend value to the array.

Definition at line 250 of file qjsonarray.h.

Here is the call graph for this function:

◆ removeAt()

void QJsonArray::removeAt ( qsizetype  i)

Removes the value at index position i. i must be a valid index position in the array (i.e., {0 <= i < size()}).

See also
insert(), replace()

Definition at line 377 of file qjsonarray.cpp.

◆ removeFirst()

void QJsonArray::removeFirst ( )
inline

Removes the first item in the array. Calling this function is equivalent to calling {removeAt(0)}. The array must not be empty. If the array can be empty, call isEmpty() before calling this function.

See also
removeAt(), removeLast()

Definition at line 89 of file qjsonarray.h.

◆ removeLast()

void QJsonArray::removeLast ( )
inline

Removes the last item in the array. Calling this function is equivalent to calling {removeAt(size() - 1)}. The array must not be empty. If the array can be empty, call isEmpty() before calling this function.

See also
removeAt(), removeFirst()

Definition at line 90 of file qjsonarray.h.

◆ replace()

void QJsonArray::replace ( qsizetype  i,
const QJsonValue value 
)

Replaces the item at index position i with value. i must be a valid index position in the array (i.e., {0 <= i < size()}).

See also
operator[](), removeAt()

Definition at line 467 of file qjsonarray.cpp.

◆ size()

qsizetype QJsonArray::size ( ) const

Returns the number of values stored in the array.

Definition at line 288 of file qjsonarray.cpp.

Here is the caller graph for this function:

◆ swap()

void QJsonArray::swap ( QJsonArray other)
inlinenoexcept
Since
5.10

Swaps the array other with this. This operation is very fast and never fails.

Definition at line 102 of file qjsonarray.h.

Here is the call graph for this function:

◆ takeAt()

QJsonValue QJsonArray::takeAt ( qsizetype  i)

Removes the item at index position i and returns it. i must be a valid index position in the array (i.e., {0 <= i < size()}).

If you don't use the return value, removeAt() is more efficient.

See also
removeAt()

Definition at line 413 of file qjsonarray.cpp.

Here is the call graph for this function:

◆ toVariantList()

QVariantList QJsonArray::toVariantList ( ) const

Converts this object to a QVariantList.

Returns the created map.

Definition at line 279 of file qjsonarray.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ const_iterator

friend class const_iterator
friend

Definition at line 220 of file qjsonarray.h.

◆ iterator

friend class iterator
friend

Definition at line 167 of file qjsonarray.h.

◆ operator<<

Q_CORE_EXPORT QDebug operator<< ( QDebug  ,
const QJsonArray  
)
friend

Definition at line 1105 of file qjsonarray.cpp.

◆ QCborArray

friend class QCborArray
friend

Definition at line 265 of file qjsonarray.h.

◆ QJsonDocument

friend class QJsonDocument
friend

Definition at line 264 of file qjsonarray.h.

◆ QJsonValue

friend class QJsonValue
friend

Definition at line 263 of file qjsonarray.h.


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