CopperSpice API  1.9.1
QJsonArray Class Reference

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

Public Typedefs

using const_iterator = QVector< QJsonValue >::const_iterator
 
using const_pointer = const QJsonValue *
 
using const_reference = QJsonValue
 
using difference_type = QVector< QJsonValue >::difference_type
 
using iterator = QVector< QJsonValue >::iterator
 
using pointer = QJsonValue *
 
using reference = QJsonValue &
 
using size_type = QVector< QJsonValue >::size_type
 

Public Methods

 QJsonArray ()
 
 QJsonArray (const QJsonArray &other)
 
 QJsonArray (const_iterator iter_begin, const_iterator iter_end)
 
 QJsonArray (QJsonArray &&other)
 
 QJsonArray (std::initializer_list< QJsonValue > args)
 
 ~QJsonArray ()
 
void append (QJsonValue value)
 
const QJsonValueat (size_type index) const
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator constBegin () const
 
const_iterator constEnd () const
 
bool contains (const QJsonValue &value) const
 
size_type count () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
iterator erase (const_iterator iter)
 
const QJsonValuefirst () const
 
iterator insert (iterator before, QJsonValue value)
 
void insert (size_type index, QJsonValue value)
 
bool isEmpty () const
 
const QJsonValuelast () const
 
bool operator!= (const QJsonArray &other) const
 
QJsonArray operator+ (QJsonValue value) const
 
QJsonArray & operator+= (QJsonValue value)
 
QJsonArray & operator<< (const QJsonValue value)
 
QJsonArray & operator= (const QJsonArray &other)
 
bool operator== (const QJsonArray &other) const
 
QJsonValueoperator[] (size_type index)
 
const QJsonValueoperator[] (size_type index) const
 
void pop_back ()
 
void pop_front ()
 
void prepend (QJsonValue value)
 
void push_back (const QJsonValue &value)
 
void push_front (const QJsonValue &value)
 
void removeAt (size_type index)
 
void removeFirst ()
 
void removeLast ()
 
void replace (size_type index, QJsonValue value)
 
size_type size () const
 
QJsonValue takeAt (size_type index)
 
QList< QVarianttoVariantList () const
 

Static Public Methods

static QJsonArray fromStringList (const QStringList &list)
 
static QJsonArray fromVariantList (const QList< QVariant > &list)
 

Friends

class QJsonValue
 

Detailed Description

The QJsonArray class encapsulates a JSON array. 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 remove() entries from it and iterate over its content using the standard C++ iterator pattern.

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

See also
JSON Support

Member Typedef Documentation

Typedef for const QJsonValue *.

Typedef for int.

Typedef for int.

Constructor & Destructor Documentation

QJsonArray::QJsonArray ( )

Creates an empty array.

QJsonArray::QJsonArray ( const_iterator  iter_begin,
const_iterator  iter_end 
)

Constructs a QJsonArray using an iterator range.

QJsonArray::QJsonArray ( const QJsonArray &  other)

Copy constructs a new QJsonArray from other.

QJsonArray::QJsonArray ( QJsonArray &&  other)

Move constructs a new QJsonArray from other.

QJsonArray::QJsonArray ( std::initializer_list< QJsonValue args)

Creates an array initialized from the args initialization list.

QJsonArray array = { 1, 2.2, QString() };
QJsonArray::~QJsonArray ( )

Deletes the array.

Method Documentation

void QJsonArray::append ( QJsonValue  value)

Inserts value at the end of the array.

See also
prepend(), insert()
const QJsonValue & QJsonArray::at ( size_type  index) const

Returns a QJsonValue representing the value for index. The returned QJsonValue is Undefined, if index is out of bounds.

iterator QJsonArray::begin ( )

Returns an STL-style iterator pointing to the first item in the array.

See also
constBegin(), end()
const_iterator QJsonArray::begin ( ) const

Returns a const STL-style iterator pointing to the first item in the array.

const_iterator QJsonArray::constBegin ( ) const

Returns a const STL-style iterator pointing to the first item in the array.

See also
begin(), constEnd()
const_iterator QJsonArray::constEnd ( ) const

Returns a const STL-style iterator pointing to the imaginary item after the last item in the array.

See also
constBegin(), end()
bool QJsonArray::contains ( const QJsonValue value) const

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

See also
count()
size_type QJsonArray::count ( ) const
inline

Equivalent to calling size().

See also
size()
bool QJsonArray::empty ( ) const
inline

This function is equivalent to isEmpty() and returns true if the array is empty.

iterator QJsonArray::end ( )

Returns an STL-style iterator pointing to the imaginary item after the last item in the array.

See also
begin(), constEnd()
const_iterator QJsonArray::end ( ) const

Returns a const STL-style iterator pointing to the imaginary item after the last item in the array.

iterator QJsonArray::erase ( const_iterator  iter)

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

See also
removeAt()
const QJsonValue & QJsonArray::first ( ) const

Returns the first value stored in the array. Equivalent to calling at(0).

See also
at()
QJsonArray QJsonArray::fromStringList ( const QStringList list)
static

Converts the string list to a QJsonArray. The values in list will be converted to JSON values.

See also
toVariantList(), QJsonValue::fromVariant()
QJsonArray QJsonArray::fromVariantList ( const QList< QVariant > &  list)
static

Converts the variant list to a QJsonArray. The QVariant values in list will be converted to JSON values.

See also
toVariantList(), QJsonValue::fromVariant()
iterator QJsonArray::insert ( iterator  before,
QJsonValue  value 
)

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

See also
erase(), insert()
void QJsonArray::insert ( size_type  index,
QJsonValue  value 
)

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

See also
append(), prepend(), replace(), removeAt()
bool QJsonArray::isEmpty ( ) const

Returns true if the object is empty. Equivalent to calling size() == 0.

See also
size()
const QJsonValue & QJsonArray::last ( ) const

Returns the last value stored in the array. Equivalent to calling at(size() - 1).

See also
at()
bool QJsonArray::operator!= ( const QJsonArray &  other) const

Returns true if this array is not equal to other.

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

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

See also
operator+=()
QJsonArray & QJsonArray::operator+= ( QJsonValue  value)

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

See also
append(), operator<<()
QJsonArray & QJsonArray::operator<< ( const QJsonValue  value)

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

See also
operator+=(), append()
QJsonArray & QJsonArray::operator= ( const QJsonArray &  other)

Copy assigns from other and returns a reference to this object.

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

Returns true if this array is equal to other.

QJsonValue & QJsonArray::operator[] ( size_type  index)

Returns the value at index position index as a reference. Index must be a valid index position in the array.

See also
at()
const QJsonValue & QJsonArray::operator[] ( size_type  index) const

Equivalent to calling at().

void QJsonArray::pop_back ( )
inline

Equivalent to removeLast(). The array must not be empty. If the array can be empty, call isEmpty() before calling this method.

void QJsonArray::pop_front ( )
inline

Equivalent to removeFirst(). The array must not be empty. If the array can be empty, call isEmpty() before calling this method.

void QJsonArray::prepend ( 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()
void QJsonArray::push_back ( const QJsonValue value)
inline

Equivalent to calling append(value).

void QJsonArray::push_front ( const QJsonValue value)
inline

Equivalent to calling prepend(value).

void QJsonArray::removeAt ( size_type  index)

Removes the value at index position index. The index must be a valid position in the array.

See also
insert(), replace()
void QJsonArray::removeFirst ( )
inline

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

See also
removeAt(), removeLast()
void QJsonArray::removeLast ( )
inline

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

See also
removeAt(), removeFirst()
void QJsonArray::replace ( size_type  index,
QJsonValue  value 
)

Replaces the item at index position index with value. The index must be a valid index position in the array.

See also
operator[](), removeAt()
size_type QJsonArray::size ( ) const

Returns the number of values stored in the array.

QJsonValue QJsonArray::takeAt ( size_type  index)

Removes the item at index position index and returns it. The index must be a valid index position in the array. If you do not use the return value, calling removeAt() is more efficient.

See also
removeAt()
QList< QVariant > QJsonArray::toVariantList ( ) const

Converts this object to a QVariantList. Returns the created map.