![]() |
Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
\inmodule QtCore\reentrant More...
#include <qjsonobject.h>
Classes | |
class | const_iterator |
\inmodule QtCore More... | |
class | iterator |
\inmodule QtCore\reentrant More... |
Public Types | |
typedef QKeyValueIterator< QAnyStringView, QJsonValueConstRef, const_iterator, QtPrivate::QJsonObjectKeyValues< QJsonValueConstRef, const_iterator > > | const_key_value_iterator |
\inmodule QtCore | |
typedef QKeyValueIterator< QAnyStringView, QJsonValueRef, iterator, QtPrivate::QJsonObjectKeyValues< QJsonValueRef, iterator > > | key_value_iterator |
\inmodule QtCore | |
typedef iterator | Iterator |
Qt-style synonym for QJsonObject::iterator. | |
typedef const_iterator | ConstIterator |
Qt-style synonym for QJsonObject::const_iterator. | |
typedef QJsonValue | mapped_type |
Typedef for QJsonValue. | |
typedef QString | key_type |
Typedef for QString. | |
typedef qsizetype | size_type |
Typedef for qsizetype. |
Public Member Functions | |
QJsonObject () | |
Constructs an empty JSON object. | |
QJsonObject (std::initializer_list< std::pair< QString, QJsonValue > > args) | |
~QJsonObject () | |
Destroys the object. | |
QJsonObject (const QJsonObject &other) noexcept | |
Creates a copy of other. | |
QJsonObject & | operator= (const QJsonObject &other) noexcept |
Assigns other to this object. | |
QJsonObject (QJsonObject &&other) noexcept | |
QJsonObject & | operator= (QJsonObject &&other) noexcept |
void | swap (QJsonObject &other) noexcept |
QVariantMap | toVariantMap () const |
Converts this object to a QVariantMap. | |
QVariantHash | toVariantHash () const |
Converts this object to a QVariantHash. | |
QStringList | keys () const |
Returns a list of all keys in this object. | |
qsizetype | size () const |
Returns the number of (key, value) pairs stored in the object. | |
qsizetype | count () 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 size(). | |
qsizetype | length () 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 size(). | |
bool | isEmpty () const |
Returns true if the object is empty. | |
QJsonValue | value (const QString &key) const |
Returns a QJsonValue representing the value for the key key. | |
QJsonValue | operator[] (const QString &key) const |
Returns a QJsonValue representing the value for the key key. | |
QJsonValueRef | operator[] (const QString &key) |
Returns a reference to the value for key. | |
QJsonValue | value (QStringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QJsonValue | value (QLatin1StringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QJsonValue | operator[] (QStringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QJsonValue | operator[] (QLatin1StringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QJsonValueRef | operator[] (QStringView key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QJsonValueRef | operator[] (QLatin1StringView key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | remove (const QString &key) |
Removes key from the object. | |
QJsonValue | take (const QString &key) |
Removes key from the object. | |
bool | contains (const QString &key) const |
Returns true if the object contains key key. | |
void | remove (QStringView key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
void | remove (QLatin1StringView key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QJsonValue | take (QStringView key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QJsonValue | take (QLatin1StringView key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
bool | contains (QStringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
bool | contains (QLatin1StringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
iterator | begin () |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the object. | |
const_iterator | begin () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const_iterator | constBegin () const |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the object. | |
iterator | end () |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the object. | |
const_iterator | end () const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const_iterator | constEnd () const |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the object. | |
key_value_iterator | keyValueBegin () |
key_value_iterator | keyValueEnd () |
const_key_value_iterator | keyValueBegin () const |
const_key_value_iterator | constKeyValueBegin () const |
const_key_value_iterator | keyValueEnd () const |
const_key_value_iterator | constKeyValueEnd () const |
iterator | erase (iterator it) |
Removes the (key, value) pair pointed to by the iterator it from the map, and returns an iterator to the next item in the map. | |
auto | asKeyValueRange () & |
auto | asKeyValueRange () const & |
auto | asKeyValueRange () && |
auto | asKeyValueRange () const && |
iterator | find (const QString &key) |
Returns an iterator pointing to the item with key key in the map. | |
const_iterator | find (const QString &key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const_iterator | constFind (const QString &key) const |
Returns a const iterator pointing to the item with key key in the map. | |
iterator | insert (const QString &key, const QJsonValue &value) |
Inserts a new item with the key key and a value of value. | |
iterator | find (QStringView key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
iterator | find (QLatin1StringView key) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const_iterator | find (QStringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const_iterator | find (QLatin1StringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const_iterator | constFind (QStringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const_iterator | constFind (QLatin1StringView key) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
iterator | insert (QStringView key, const QJsonValue &value) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
iterator | insert (QLatin1StringView key, const QJsonValue &value) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
bool | empty () const |
This function is provided for STL compatibility. |
Static Public Member Functions | |
static QJsonObject | fromVariantMap (const QVariantMap &map) |
Converts the variant map map to a QJsonObject. | |
static QJsonObject | fromVariantHash (const QVariantHash &map) |
Converts the variant hash hash to a QJsonObject. |
Friends | |
class | iterator |
class | const_iterator |
class | QJsonValue |
class | QJsonDocument |
class | QJsonPrivate::Value |
class | QJsonValueConstRef |
class | QJsonValueRef |
class | QCborMap |
Q_CORE_EXPORT bool | comparesEqual (const QJsonObject &lhs, const QJsonObject &rhs) |
bool | comparesEqual (const QJsonObject &lhs, const QJsonValue &rhs) |
bool | comparesEqual (const QJsonObject &lhs, const QJsonValueConstRef &rhs) |
Q_CORE_EXPORT QDebug | operator<< (QDebug dbg, const QJsonObject &o) |
\inmodule QtCore
\reentrant
The QJsonObject class encapsulates a JSON object.
\compares equality \compareswith equality QJsonValue QJsonValueConstRef \endcompareswith
A JSON object is a list of key value pairs, where the keys are unique strings and the values are represented by a QJsonValue.
A QJsonObject can be converted to and from a QVariantMap. You can query the number of (key, value) pairs with size(), insert(), and remove() entries from it and iterate over its content using the standard C++ iterator pattern.
QJsonObject 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 object to and from text based JSON through QJsonDocument.
Definition at line 33 of file qjsonobject.h.
typedef QKeyValueIterator<QAnyStringView, QJsonValueConstRef, const_iterator, QtPrivate::QJsonObjectKeyValues<QJsonValueConstRef, const_iterator> > QJsonObject::const_key_value_iterator |
\inmodule QtCore
The QJsonObject::const_key_value_iterator typedef provides an STL-style iterator for QJsonObject.
QJsonObject::const_key_value_iterator is essentially the same as QJsonObject::const_iterator with the difference that operator*() returns a key/value pair instead of a value.
Definition at line 300 of file qjsonobject.h.
Qt-style synonym for QJsonObject::const_iterator.
Definition at line 333 of file qjsonobject.h.
typedef iterator QJsonObject::Iterator |
Qt-style synonym for QJsonObject::iterator.
Definition at line 332 of file qjsonobject.h.
typedef QString QJsonObject::key_type |
typedef QKeyValueIterator<QAnyStringView, QJsonValueRef, iterator, QtPrivate::QJsonObjectKeyValues<QJsonValueRef, iterator> > QJsonObject::key_value_iterator |
\inmodule QtCore
The QJsonObject::key_value_iterator typedef provides an STL-style iterator for QJsonObject.
QJsonObject::key_value_iterator is essentially the same as QJsonObject::iterator with the difference that operator*() returns a key/value pair instead of a value.
Definition at line 303 of file qjsonobject.h.
typedef QJsonValue QJsonObject::mapped_type |
Typedef for QJsonValue.
Provided for STL compatibility.
Definition at line 348 of file qjsonobject.h.
typedef qsizetype QJsonObject::size_type |
Typedef for qsizetype.
Provided for STL compatibility.
Definition at line 350 of file qjsonobject.h.
|
default |
Constructs an empty JSON object.
QJsonObject::QJsonObject | ( | std::initializer_list< std::pair< QString, QJsonValue > > | args | ) |
Definition at line 119 of file qjsonobject.cpp.
|
default |
Destroys the object.
|
defaultnoexcept |
Creates a copy of other.
Since QJsonObject is implicitly shared, the copy is shallow as long as the object does not get modified.
|
noexcept |
|
inline |
Definition at line 323 of file qjsonobject.h.
|
inline |
Definition at line 325 of file qjsonobject.h.
|
inline |
Definition at line 324 of file qjsonobject.h.
|
inline |
Definition at line 326 of file qjsonobject.h.
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first item in the object.
Definition at line 306 of file qjsonobject.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 307 of file qjsonobject.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first item in the object.
Definition at line 308 of file qjsonobject.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the object.
Definition at line 311 of file qjsonobject.h.
QJsonObject::const_iterator QJsonObject::constFind | ( | const QString & | key | ) | const |
Returns a const iterator pointing to the item with key key in the map.
If the map contains no item with key key, the function returns constEnd().
Definition at line 735 of file qjsonobject.cpp.
QJsonObject::const_iterator QJsonObject::constFind | ( | QLatin1StringView | key | ) | const |
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 753 of file qjsonobject.cpp.
QJsonObject::const_iterator QJsonObject::constFind | ( | QStringView | key | ) | const |
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 744 of file qjsonobject.cpp.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first entry in the object.
Definition at line 315 of file qjsonobject.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary entry after the last entry in the ibject.
Definition at line 320 of file qjsonobject.h.
bool QJsonObject::contains | ( | const QString & | key | ) | const |
Returns true
if the object contains key key.
Definition at line 582 of file qjsonobject.cpp.
bool QJsonObject::contains | ( | QLatin1StringView | key | ) | const |
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 600 of file qjsonobject.cpp.
bool QJsonObject::contains | ( | QStringView | key | ) | const |
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 591 of file qjsonobject.cpp.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Same as size().
Definition at line 65 of file qjsonobject.h.
|
inline |
This function is provided for STL compatibility.
It is equivalent to isEmpty(), returning true
if the object is empty; otherwise returning false
.
Definition at line 352 of file qjsonobject.h.
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary item after the last item in the object.
Definition at line 309 of file qjsonobject.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 310 of file qjsonobject.h.
QJsonObject::iterator QJsonObject::erase | ( | QJsonObject::iterator | it | ) |
Removes the (key, value) pair pointed to by the iterator it from the map, and returns an iterator to the next item in the map.
Definition at line 657 of file qjsonobject.cpp.
QJsonObject::iterator QJsonObject::find | ( | const QString & | key | ) |
Returns an iterator pointing to the item with key key in the map.
If the map contains no item with key key, the function returns end().
Definition at line 674 of file qjsonobject.cpp.
|
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 335 of file qjsonobject.h.
QJsonObject::iterator QJsonObject::find | ( | QLatin1StringView | key | ) |
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 692 of file qjsonobject.cpp.
|
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 341 of file qjsonobject.h.
QJsonObject::iterator QJsonObject::find | ( | QStringView | key | ) |
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 683 of file qjsonobject.cpp.
|
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 340 of file qjsonobject.h.
|
static |
Converts the variant hash hash to a QJsonObject.
The keys in hash will be used as the keys in the JSON object, and the QVariant values will be converted to JSON values.
Definition at line 204 of file qjsonobject.cpp.
|
static |
Converts the variant map map to a QJsonObject.
The keys in map will be used as the keys in the JSON object, and the QVariant values will be converted to JSON values.
Definition at line 175 of file qjsonobject.cpp.
QJsonObject::iterator QJsonObject::insert | ( | const QString & | key, |
const QJsonValue & | value ) |
Inserts a new item with the key key and a value of value.
If there is already an item with the key key, then that item's value is replaced with value.
Returns an iterator pointing to the inserted item.
If the value is QJsonValue::Undefined, it will cause the key to get removed from the object. The returned iterator will then point to end().
Definition at line 422 of file qjsonobject.cpp.
QJsonObject::iterator QJsonObject::insert | ( | QLatin1StringView | key, |
const QJsonValue & | value ) |
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 440 of file qjsonobject.cpp.
QJsonObject::iterator QJsonObject::insert | ( | QStringView | key, |
const QJsonValue & | value ) |
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 431 of file qjsonobject.cpp.
bool QJsonObject::isEmpty | ( | ) | const |
Returns true
if the object is empty.
This is the same as size() == 0.
Definition at line 257 of file qjsonobject.cpp.
QStringList QJsonObject::keys | ( | ) | const |
Returns a list of all keys in this object.
The list is sorted alphabetically.
Definition at line 233 of file qjsonobject.cpp.
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the first entry in the object.
Definition at line 312 of file qjsonobject.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the first entry in the object.
Definition at line 314 of file qjsonobject.h.
|
inline |
Returns an \l{STL-style iterators}{STL-style iterator} pointing to the imaginary entry after the last entry in the object.
Definition at line 313 of file qjsonobject.h.
|
inline |
Returns a const \l{STL-style iterators}{STL-style iterator} pointing to the imaginary entry after the last entry in the object.
Definition at line 319 of file qjsonobject.h.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Same as size().
Definition at line 66 of file qjsonobject.h.
|
defaultnoexcept |
Assigns other to this object.
|
inlinenoexcept |
QJsonValueRef QJsonObject::operator[] | ( | const QString & | key | ) |
Returns a reference to the value for key.
If there is no value with key key in the object, one is created with a QJsonValue::Null value and then returned.
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 element in the QJsonArray or QJsonObject from which you got the reference.
Definition at line 366 of file qjsonobject.cpp.
QJsonValue QJsonObject::operator[] | ( | const QString & | key | ) | const |
Returns a QJsonValue representing the value for the key key.
This does the same as value().
The returned QJsonValue is QJsonValue::Undefined if the key does not exist.
Definition at line 334 of file qjsonobject.cpp.
QJsonValueRef QJsonObject::operator[] | ( | QLatin1StringView | key | ) |
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 384 of file qjsonobject.cpp.
|
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 75 of file qjsonobject.h.
QJsonValueRef QJsonObject::operator[] | ( | QStringView | key | ) |
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 375 of file qjsonobject.cpp.
|
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 74 of file qjsonobject.h.
Removes key from the object.
Definition at line 485 of file qjsonobject.cpp.
void QJsonObject::remove | ( | QLatin1StringView | key | ) |
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 503 of file qjsonobject.cpp.
void QJsonObject::remove | ( | QStringView | key | ) |
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 494 of file qjsonobject.cpp.
qsizetype QJsonObject::size | ( | ) | const |
Returns the number of (key, value) pairs stored in the object.
Definition at line 247 of file qjsonobject.cpp.
|
inlinenoexcept |
Definition at line 53 of file qjsonobject.h.
QJsonValue QJsonObject::take | ( | const QString & | key | ) |
Removes key from the object.
Returns a QJsonValue containing the value referenced by key. If key was not contained in the object, the returned QJsonValue is QJsonValue::Undefined.
Definition at line 534 of file qjsonobject.cpp.
QJsonValue QJsonObject::take | ( | QLatin1StringView | key | ) |
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 552 of file qjsonobject.cpp.
QJsonValue QJsonObject::take | ( | QStringView | key | ) |
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 543 of file qjsonobject.cpp.
QVariantHash QJsonObject::toVariantHash | ( | ) | const |
Converts this object to a QVariantHash.
Returns the created hash.
Definition at line 222 of file qjsonobject.cpp.
QVariantMap QJsonObject::toVariantMap | ( | ) | const |
Converts this object to a QVariantMap.
Returns the created map.
Definition at line 187 of file qjsonobject.cpp.
QJsonValue QJsonObject::value | ( | const QString & | key | ) | const |
Returns a QJsonValue representing the value for the key key.
The returned QJsonValue is QJsonValue::Undefined if the key does not exist.
Definition at line 286 of file qjsonobject.cpp.
QJsonValue QJsonObject::value | ( | QLatin1StringView | key | ) | const |
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 304 of file qjsonobject.cpp.
QJsonValue QJsonObject::value | ( | QStringView | key | ) | const |
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 295 of file qjsonobject.cpp.
|
friend |
Definition at line 624 of file qjsonobject.cpp.
|
friend |
Definition at line 357 of file qjsonobject.h.
|
friend |
Definition at line 361 of file qjsonobject.h.
|
friend |
Definition at line 296 of file qjsonobject.h.
|
friend |
Definition at line 205 of file qjsonobject.h.
|
friend |
Definition at line 1560 of file qjsonobject.cpp.
|
friend |
Definition at line 373 of file qjsonobject.h.
|
friend |
Definition at line 369 of file qjsonobject.h.
|
friend |
Definition at line 370 of file qjsonobject.h.
|
friend |
Definition at line 368 of file qjsonobject.h.
|
friend |
Definition at line 371 of file qjsonobject.h.
|
friend |
Definition at line 372 of file qjsonobject.h.