QtBase
v6.3.1
|
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_type * | pointer |
typedef const value_type * | const_pointer |
typedef QJsonValueRef | reference |
typedef QJsonValue | const_reference |
typedef qsizetype | difference_type |
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 &) |
The QJsonArray class encapsulates a JSON array.
\inmodule QtCore
\reentrant
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.
Definition at line 53 of file qjsonarray.h.
Typedef for const QJsonValue *. Provided for STL compatibility.
Definition at line 257 of file qjsonarray.h.
Typedef for const QJsonValue &. Provided for STL compatibility.
Definition at line 259 of file qjsonarray.h.
Qt-style synonym for QJsonArray::const_iterator.
Definition at line 238 of file qjsonarray.h.
Typedef for qsizetype. Provided for STL compatibility.
Definition at line 260 of file qjsonarray.h.
Qt-style synonym for QJsonArray::iterator.
Definition at line 237 of file qjsonarray.h.
Typedef for QJsonValue *. Provided for STL compatibility.
Definition at line 256 of file qjsonarray.h.
Typedef for QJsonValue &. Provided for STL compatibility.
Definition at line 258 of file qjsonarray.h.
Typedef for qsizetype. Provided for STL compatibility.
Definition at line 254 of file qjsonarray.h.
Typedef for QJsonValue. Provided for STL compatibility.
Definition at line 255 of file qjsonarray.h.
|
default |
Creates an empty array.
QJsonArray::QJsonArray | ( | std::initializer_list< QJsonValue > | args | ) |
QJsonArray can be constructed in a way similar to JSON notation, for example:
Definition at line 166 of file qjsonarray.cpp.
|
default |
Deletes the array.
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.
|
noexcept |
Move-constructs a QJsonArray from other.
Definition at line 183 of file qjsonarray.cpp.
void QJsonArray::append | ( | const QJsonValue & | value | ) |
Inserts value at the end of the array.
Definition at line 366 of file qjsonarray.cpp.
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.
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array.
Definition at line 223 of file qjsonarray.h.
|
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.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array.
Definition at line 226 of file qjsonarray.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array.
Definition at line 230 of file qjsonarray.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the array.
Definition at line 225 of file qjsonarray.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array.
Definition at line 229 of file qjsonarray.h.
bool QJsonArray::contains | ( | const QJsonValue & | value | ) | const |
Returns true
if the array contains an occurrence of value, otherwise false
.
Definition at line 479 of file qjsonarray.cpp.
|
inline |
|
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.
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the array.
Definition at line 227 of file qjsonarray.h.
|
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.
|
inline |
Removes the item pointed to by it, and returns an iterator pointing to the next item.
Definition at line 233 of file qjsonarray.h.
QJsonValue QJsonArray::first | ( | ) | const |
Returns the first value stored in the array.
Same as at(0)
.
Definition at line 332 of file qjsonarray.cpp.
|
static |
Converts the string list list to a QJsonArray.
The values in list will be converted to JSON values.
Definition at line 251 of file qjsonarray.cpp.
|
static |
Converts the variant list list to a QJsonArray.
The QVariant values in list will be converted to JSON values.
Definition at line 269 of file qjsonarray.cpp.
|
inline |
Inserts value before the position pointed to by before, and returns an iterator pointing to the newly inserted item.
Definition at line 231 of file qjsonarray.h.
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.
Definition at line 431 of file qjsonarray.cpp.
bool QJsonArray::isEmpty | ( | ) | const |
Returns true
if the object is empty. This is the same as size() == 0.
Definition at line 306 of file qjsonarray.cpp.
QJsonValue QJsonArray::last | ( | ) | const |
Returns the last value stored in the array.
Same as {at(size() - 1)}.
Definition at line 344 of file qjsonarray.cpp.
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.
|
inline |
Returns an array that contains all the items in this array followed by the provided value.
Definition at line 241 of file qjsonarray.h.
|
inline |
Appends value to the array, and returns a reference to the array itself.
Definition at line 243 of file qjsonarray.h.
|
inline |
Appends value to the array, and returns a reference to the array itself.
Definition at line 245 of file qjsonarray.h.
QJsonArray & QJsonArray::operator= | ( | const QJsonArray & | other | ) |
Assigns other to this array.
Definition at line 192 of file qjsonarray.cpp.
|
inlinenoexcept |
Move-assigns other to this array.
Definition at line 67 of file qjsonarray.h.
bool QJsonArray::operator== | ( | const QJsonArray & | other | ) | const |
Returns true
if this array is equal to other.
Definition at line 520 of file qjsonarray.cpp.
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.
Definition at line 501 of file qjsonarray.cpp.
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.
|
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.
|
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.
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.
Definition at line 356 of file qjsonarray.cpp.
|
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.
|
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.
Removes the value at index position i. i must be a valid index position in the array (i.e., {0 <= i < size()}).
Definition at line 377 of file qjsonarray.cpp.
|
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.
Definition at line 89 of file qjsonarray.h.
|
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.
Definition at line 90 of file qjsonarray.h.
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()}).
Definition at line 467 of file qjsonarray.cpp.
qsizetype QJsonArray::size | ( | ) | const |
Returns the number of values stored in the array.
Definition at line 288 of file qjsonarray.cpp.
|
inlinenoexcept |
Swaps the array other with this. This operation is very fast and never fails.
Definition at line 102 of file qjsonarray.h.
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.
Definition at line 413 of file qjsonarray.cpp.
QVariantList QJsonArray::toVariantList | ( | ) | const |
Converts this object to a QVariantList.
Returns the created map.
Definition at line 279 of file qjsonarray.cpp.
|
friend |
Definition at line 220 of file qjsonarray.h.
|
friend |
Definition at line 167 of file qjsonarray.h.
|
friend |
Definition at line 1105 of file qjsonarray.cpp.
|
friend |
Definition at line 265 of file qjsonarray.h.
|
friend |
Definition at line 264 of file qjsonarray.h.
|
friend |
Definition at line 263 of file qjsonarray.h.