QJsonArray Class▲
-
Header: QJsonArray
-
Since: Qt 5.0
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
-
qmake: QT += core
-
Group: QJsonArray is part of JSON Support in Qt, Implicitly Shared Classes, qtserialization
Detailed Description▲
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▲
See also JSON Support in Qt, JSON Save Game Example
Member Type Documentation▲
QJsonArray::ConstIterator▲
Qt-style synonym for QJsonArray::const_iterator.
QJsonArray::Iterator▲
Qt-style synonym for QJsonArray::iterator.
QJsonArray::const_pointer▲
Typedef for const QJsonValue *. Provided for STL compatibility.
QJsonArray::const_reference▲
Typedef for const QJsonValue &. Provided for STL compatibility.
QJsonArray::difference_type▲
Typedef for qsizetype. Provided for STL compatibility.
QJsonArray::pointer▲
Typedef for QJsonValue *. Provided for STL compatibility.
QJsonArray::reference▲
Typedef for QJsonValue &. Provided for STL compatibility.
QJsonArray::size_type▲
Typedef for qsizetype. Provided for STL compatibility.
QJsonArray::value_type▲
Typedef for QJsonValue. Provided for STL compatibility.
Member Function Documentation▲
QJsonArray::QJsonArray()▲
Creates an empty array.
[since 5.4] QJsonArray::QJsonArray(std::initializer_list<QJsonValue> args)▲
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() }
;
This function was introduced in Qt 5.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.
[since 5.10] QJsonArray::QJsonArray(QJsonArray &&other)▲
Move-constructs a QJsonArray from other.
This function was introduced in Qt 5.10.
QJsonArray::~QJsonArray()▲
Deletes the array.
void QJsonArray::append(const QJsonValue &value)▲
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.
QJsonArray::iterator QJsonArray::begin()▲
Returns an STL-style iterator pointing to the first item in the array.
See Also▲
See also constBegin(), end()
QJsonArray::const_iterator QJsonArray::begin() const▲
This is an overloaded function.
QJsonArray::const_iterator QJsonArray::cbegin() const▲
Returns a const STL-style iterator pointing to the first item in the array.
See Also▲
QJsonArray::const_iterator QJsonArray::cend() const▲
Returns a const STL-style iterator pointing to the imaginary item after the last item in the array.
See Also▲
QJsonArray::const_iterator QJsonArray::constBegin() const▲
Returns a const STL-style iterator pointing to the first item in the array.
See Also▲
QJsonArray::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▲
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▲
See also count()
qsizetype QJsonArray::count() const▲
bool QJsonArray::empty() const▲
This function is provided for STL compatibility. It is equivalent to isEmpty() and returns true if the array is empty.
QJsonArray::iterator QJsonArray::end()▲
Returns an STL-style iterator pointing to the imaginary item after the last item in the array.
See Also▲
QJsonArray::const_iterator QJsonArray::end() const▲
This is an overloaded function.
QJsonArray::iterator QJsonArray::erase(QJsonArray::iterator it)▲
Removes the item pointed to by it, and returns an iterator pointing to the next item.
See Also▲
See also removeAt()
QJsonValue QJsonArray::first() const▲
[static] QJsonArray QJsonArray::fromStringList(const QStringList &list)▲
Converts the string list list to a QJsonArray.
The values in list will be converted to JSON values.
See Also▲
See also toVariantList(), QJsonValue::fromVariant()
[static] QJsonArray QJsonArray::fromVariantList(const QVariantList &list)▲
Converts the variant list list to a QJsonArray.
The QVariant values in list will be converted to JSON values.
Conversion from QVariant is not completely lossless. Please see the documentation in QJsonValue::fromVariant() for more information.
See Also▲
See also toVariantList(), QJsonValue::fromVariant()
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▲
QJsonArray::iterator QJsonArray::insert(QJsonArray::iterator before, const QJsonValue &value)▲
Inserts value before the position pointed to by before, and returns an iterator pointing to the newly inserted item.
See Also▲
bool QJsonArray::isEmpty() const▲
QJsonValue QJsonArray::last() const▲
void QJsonArray::pop_back()▲
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.
void QJsonArray::pop_front()▲
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.
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▲
void QJsonArray::push_back(const QJsonValue &value)▲
This function is provided for STL compatibility. It is equivalent to append(value) and will append value to the array.
void QJsonArray::push_front(const QJsonValue &value)▲
This function is provided for STL compatibility. It is equivalent to prepend(value) and will prepend value to the array.
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▲
void QJsonArray::removeFirst()▲
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▲
See also removeAt(), removeLast()
void QJsonArray::removeLast()▲
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▲
See also removeAt(), removeFirst()
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▲
See also operator[](), removeAt()
qsizetype QJsonArray::size() const▲
Returns the number of values stored in the array.
[since 5.10] void QJsonArray::swap(QJsonArray &other)▲
Swaps the array other with this. This operation is very fast and never fails.
This function was introduced in Qt 5.10.
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▲
See also removeAt()
QVariantList QJsonArray::toVariantList() const▲
Converts this object to a QVariantList.
Returns the created map.
bool QJsonArray::operator!=(const QJsonArray &other) const▲
Returns true if this array is not equal to other.
[since 5.3] QJsonArray QJsonArray::operator+(const QJsonValue &value) const▲
Returns an array that contains all the items in this array followed by the provided value.
This function was introduced in Qt 5.3.
See Also▲
See also operator+=()
[since 5.3] QJsonArray &QJsonArray::operator+=(const QJsonValue &value)▲
Appends value to the array, and returns a reference to the array itself.
This function was introduced in Qt 5.3.
See Also▲
See also append(), operator<<()
[since 5.3] QJsonArray &QJsonArray::operator<<(const QJsonValue &value)▲
Appends value to the array, and returns a reference to the array itself.
This function was introduced in Qt 5.3.
See Also▲
See also operator+=(), append()
QJsonArray &QJsonArray::operator=(const QJsonArray &other)▲
Assigns other to this array.
[since 5.10] QJsonArray &QJsonArray::operator=(QJsonArray &&other)▲
Move-assigns other to this array.
This function was introduced in Qt 5.10.
bool QJsonArray::operator==(const QJsonArray &other) const▲
Returns true if this array is equal to other.
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▲
See also at()
QJsonValue QJsonArray::operator[](qsizetype i) const▲
This is an overloaded function.
Same as at().