QJsonObject 類

QJsonObject 類封裝 JSON 對象。 更多...

頭: #include <QJsonObject>
qmake: QT += core
Since: Qt 5.0

該類在 Qt 5.0 引入。

注意: 此類的所有函數 可重入 .

公共類型

class const_iterator
class iterator
typedef ConstIterator
typedef Iterator
typedef key_type
typedef mapped_type
typedef size_type

公共函數

QJsonObject (QJsonObject && other )
QJsonObject (const QJsonObject & other )
QJsonObject (std::initializer_list<QPair<QString, QJsonValue>> args )
QJsonObject ()
QJsonObject & operator= (QJsonObject && other )
QJsonObject & operator= (const QJsonObject & other )
~QJsonObject ()
QJsonObject::iterator begin ()
QJsonObject::const_iterator begin () const
QJsonObject::const_iterator constBegin () const
QJsonObject::const_iterator constEnd () const
QJsonObject::const_iterator constFind (const QString & key ) const
QJsonObject::const_iterator constFind (QStringView key ) const
QJsonObject::const_iterator constFind (QLatin1String key ) const
bool contains (const QString & key ) const
bool contains (QStringView key ) const
bool contains (QLatin1String key ) const
int count () const
bool empty () const
QJsonObject::iterator end ()
QJsonObject::const_iterator end () const
QJsonObject::iterator erase (QJsonObject::iterator it )
QJsonObject::iterator find (const QString & key )
QJsonObject::const_iterator find (const QString & key ) const
QJsonObject::iterator find (QStringView key )
QJsonObject::iterator find (QLatin1String key )
QJsonObject::const_iterator find (QStringView key ) const
QJsonObject::const_iterator find (QLatin1String key ) const
QJsonObject::iterator insert (const QString & key , const QJsonValue & value )
QJsonObject::iterator insert (QStringView key , const QJsonValue & value )
QJsonObject::iterator insert (QLatin1String key , const QJsonValue & value )
bool isEmpty () const
QStringList keys () const
int length () const
void remove (const QString & key )
void remove (QStringView key )
void remove (QLatin1String key )
int size () const
void swap (QJsonObject & other )
QJsonValue take (const QString & key )
QJsonValue take (QStringView key )
QJsonValue take (QLatin1String key )
QVariantHash toVariantHash () const
QVariantMap toVariantMap () const
QJsonValue value (const QString & key ) const
QJsonValue value (QStringView key ) const
QJsonValue value (QLatin1String key ) const
bool operator!= (const QJsonObject & other ) const
bool operator== (const QJsonObject & other ) const
QJsonValue operator[] (const QString & key ) const
QJsonValueRef operator[] (const QString & key )
QJsonValue operator[] (QStringView key ) const
QJsonValue operator[] (QLatin1String key ) const
QJsonValueRef operator[] (QStringView key )
QJsonValueRef operator[] (QLatin1String key )

靜態公共成員

QJsonObject fromVariantHash (const QVariantHash & hash )
QJsonObject fromVariantMap (const QVariantMap & map )

詳細描述

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 (),和 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 .

另請參閱 在 Qt 中支持 JSON and JSON 保存遊戲範例 .

成員類型文檔編製

typedef QJsonObject:: ConstIterator

Qt 樣式同義詞 QJsonObject::const_iterator .

typedef QJsonObject:: Iterator

Qt 樣式同義詞 QJsonObject::iterator .

typedef QJsonObject:: key_type

typedef 對於 QString . Provided for STL compatibility.

typedef QJsonObject:: mapped_type

typedef 對於 QJsonValue . Provided for STL compatibility.

typedef QJsonObject:: size_type

typedef 對於 int。為兼容 STL 提供。

成員函數文檔編製

QJsonObject:: QJsonObject ( QJsonObject && other )

移動構造 QJsonObject,從 other .

該函數在 Qt 5.10 引入。

QJsonObject:: QJsonObject (const QJsonObject & other )

創建副本為 other .

Since QJsonObject is implicitly shared, the copy is shallow as long as the object does not get modified.

QJsonObject:: QJsonObject ( std::initializer_list < QPair < QString , QJsonValue >> args )

Constructs a QJsonObject instance initialized from args initialization list. For example:

QJsonObject object
{
    {"property1", 1},
    {"property2", 2}
};
					

該函數在 Qt 5.4 引入。

QJsonObject:: QJsonObject ()

構造空的 JSON 對象。

另請參閱 isEmpty ().

QJsonObject &QJsonObject:: operator= ( QJsonObject && other )

移動賦值 other 到此對象。

該函數在 Qt 5.10 引入。

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

賦值 other 到此對象。

QJsonObject:: ~QJsonObject ()

銷毀對象。

QJsonObject::iterator QJsonObject:: begin ()

返迴 STL 樣式迭代器 pointing to the first item in the object.

另請參閱 constBegin () 和 end ().

QJsonObject::const_iterator QJsonObject:: begin () const

這是重載函數。

QJsonObject::const_iterator QJsonObject:: constBegin () const

返迴常量 STL 樣式迭代器 pointing to the first item in the object.

另請參閱 begin () 和 constEnd ().

QJsonObject::const_iterator QJsonObject:: constEnd () const

返迴常量 STL 樣式迭代器 pointing to the imaginary item after the last item in the object.

另請參閱 constBegin () 和 end ().

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 ,函數返迴 constEnd ().

QJsonObject::const_iterator QJsonObject:: constFind ( QStringView key ) const

這是重載函數。

該函數在 Qt 5.14 引入。

QJsonObject::const_iterator QJsonObject:: constFind ( QLatin1String key ) const

這是重載函數。

該函數在 Qt 5.7 引入。

bool QJsonObject:: contains (const QString & key ) const

返迴 true if the object contains key key .

另請參閱 insert (), remove (),和 take ().

bool QJsonObject:: contains ( QStringView key ) const

這是重載函數。

該函數在 Qt 5.14 引入。

bool QJsonObject:: contains ( QLatin1String key ) const

這是重載函數。

該函數在 Qt 5.7 引入。

int QJsonObject:: count () const

這是重載函數。

如同 size ().

bool QJsonObject:: empty () const

此函數為兼容 STL (標準模闆庫) 提供。它相當於 isEmpty (), returning true if the object is empty; otherwise returning false .

QJsonObject::iterator QJsonObject:: end ()

返迴 STL 樣式迭代器 pointing to the imaginary item after the last item in the object.

另請參閱 begin () 和 constEnd ().

QJsonObject::const_iterator QJsonObject:: end () const

這是重載函數。

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.

另請參閱 remove ().

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 ,函數返迴 end ().

QJsonObject::const_iterator QJsonObject:: find (const QString & key ) const

這是重載函數。

QJsonObject::iterator QJsonObject:: find ( QStringView key )

這是重載函數。

該函數在 Qt 5.14 引入。

QJsonObject::iterator QJsonObject:: find ( QLatin1String key )

這是重載函數。

該函數在 Qt 5.7 引入。

QJsonObject::const_iterator QJsonObject:: find ( QStringView key ) const

這是重載函數。

該函數在 Qt 5.14 引入。

QJsonObject::const_iterator QJsonObject:: find ( QLatin1String key ) const

這是重載函數。

該函數在 Qt 5.7 引入。

[static] QJsonObject QJsonObject:: fromVariantHash (const QVariantHash & hash )

Converts the variant hash hash 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.

注意: Conversion from QVariant is not completely lossless. Please see the documentation in QJsonValue::fromVariant () 瞭解更多信息。

該函數在 Qt 5.5 引入。

另請參閱 fromVariantMap (), toVariantHash (),和 QJsonValue::fromVariant ().

[static] QJsonObject QJsonObject:: fromVariantMap (const QVariantMap & map )

Converts the variant map map 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.

注意: Conversion from QVariant is not completely lossless. Please see the documentation in QJsonValue::fromVariant () 瞭解更多信息。

另請參閱 fromVariantHash (), toVariantMap (),和 QJsonValue::fromVariant ().

QJsonObject::iterator QJsonObject:: insert (const QString & key , const QJsonValue & value )

Inserts a new item with the key key 和值 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 ().

另請參閱 remove (), take (), QJsonObject::iterator ,和 end ().

QJsonObject::iterator QJsonObject:: insert ( QStringView key , const QJsonValue & value )

這是重載函數。

該函數在 Qt 5.14 引入。

QJsonObject::iterator QJsonObject:: insert ( QLatin1String key , const QJsonValue & value )

這是重載函數。

該函數在 Qt 5.14 引入。

bool QJsonObject:: isEmpty () const

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

另請參閱 size ().

QStringList QJsonObject:: keys () const

返迴在此對象中的所有鍵列錶。

The list is sorted lexographically.

int QJsonObject:: length () const

這是重載函數。

如同 size ().

void QJsonObject:: remove (const QString & key )

移除 key 從對象。

另請參閱 insert () 和 take ().

void QJsonObject:: remove ( QStringView key )

這是重載函數。

該函數在 Qt 5.14 引入。

void QJsonObject:: remove ( QLatin1String key )

這是重載函數。

該函數在 Qt 5.14 引入。

int QJsonObject:: size () const

Returns the number of (key, value) pairs stored in the object.

void QJsonObject:: swap ( QJsonObject & other )

Swaps the object other 與此。此操作很快且從不失敗。

該函數在 Qt 5.10 引入。

QJsonValue QJsonObject:: take (const QString & key )

移除 key 從對象。

返迴 QJsonValue containing the value referenced by key 。若 key was not contained in the object, the returned QJsonValue is QJsonValue::Undefined .

另請參閱 insert (), remove (),和 QJsonValue .

QJsonValue QJsonObject:: take ( QStringView key )

這是重載函數。

該函數在 Qt 5.14 引入。

QJsonValue QJsonObject:: take ( QLatin1String key )

這是重載函數。

該函數在 Qt 5.14 引入。

QVariantHash QJsonObject:: toVariantHash () const

把此對象轉換成 QVariantHash .

返迴創建的哈希。

該函數在 Qt 5.5 引入。

另請參閱 toVariantMap ().

QVariantMap QJsonObject:: toVariantMap () const

把此對象轉換成 QVariantMap .

返迴創建的映射。

另請參閱 toVariantHash ().

QJsonValue QJsonObject:: value (const QString & key ) const

返迴 QJsonValue 錶示值為鍵 key .

返迴的 QJsonValue is QJsonValue::Undefined 若鍵不存在。

另請參閱 QJsonValue and QJsonValue::isUndefined ().

QJsonValue QJsonObject:: value ( QStringView key ) const

這是重載函數。

該函數在 Qt 5.14 引入。

QJsonValue QJsonObject:: value ( QLatin1String key ) const

這是重載函數。

該函數在 Qt 5.7 引入。

bool QJsonObject:: operator!= (const QJsonObject & other ) const

返迴 true if other is not equal to this object.

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

返迴 true if other is equal to this object.

QJsonValue QJsonObject:: operator[] (const QString & key ) const

返迴 QJsonValue 錶示值為鍵 key .

This does the same as value ().

返迴的 QJsonValue is QJsonValue::Undefined 若鍵不存在。

另請參閱 value (), QJsonValue ,和 QJsonValue::isUndefined ().

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.

另請參閱 value ().

QJsonValue QJsonObject:: operator[] ( QStringView key ) const

這是重載函數。

該函數在 Qt 5.14 引入。

QJsonValue QJsonObject:: operator[] ( QLatin1String key ) const

這是重載函數。

該函數在 Qt 5.7 引入。

QJsonValueRef QJsonObject:: operator[] ( QStringView key )

這是重載函數。

該函數在 Qt 5.14 引入。

QJsonValueRef QJsonObject:: operator[] ( QLatin1String key )

這是重載函數。

該函數在 Qt 5.7 引入。