QJsonObject 类封装 JSON 对象。 更多...
| 头: |
#include <QJsonObject>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
|
| qmake: |
QT += core
|
此类 相等可比较 .
此类 相等可比较 with QJsonValue and QJsonValueConstRef.
注意: 此类的所有函数 可重入 .
| class | const_iterator |
| class | iterator |
| ConstIterator | |
| Iterator | |
(从 6.10 起)
|
const_key_value_iterator |
| key_type | |
(从 6.10 起)
|
key_value_iterator |
| mapped_type | |
| size_type |
| QJsonObject () | |
| QJsonObject (std::initializer_list<std::pair<QString, QJsonValue>> args ) | |
| QJsonObject (const QJsonObject & other ) | |
| QJsonObject (QJsonObject && other ) | |
| ~QJsonObject () | |
(从 6.10 起)
auto
|
asKeyValueRange () && |
(从 6.10 起)
auto
|
asKeyValueRange () & |
(从 6.10 起)
auto
|
asKeyValueRange () const && |
(从 6.10 起)
auto
|
asKeyValueRange () const & |
| 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 (QLatin1StringView key ) const |
| QJsonObject::const_iterator | constFind (QStringView key ) const |
(从 6.10 起)
QJsonObject::const_key_value_iterator
|
constKeyValueBegin () const |
(从 6.10 起)
QJsonObject::const_key_value_iterator
|
constKeyValueEnd () const |
| bool | contains (const QString & key ) const |
| bool | contains (QLatin1StringView key ) const |
| bool | contains (QStringView key ) const |
| qsizetype | 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::iterator | find (QLatin1StringView key ) |
| QJsonObject::iterator | find (QStringView key ) |
| QJsonObject::const_iterator | find (QLatin1StringView key ) const |
| QJsonObject::const_iterator | find (QStringView key ) const |
| QJsonObject::const_iterator | find (const QString & key ) const |
| QJsonObject::iterator | insert (const QString & key , const QJsonValue & value ) |
| QJsonObject::iterator | insert (QLatin1StringView key , const QJsonValue & value ) |
| QJsonObject::iterator | insert (QStringView key , const QJsonValue & value ) |
| bool | isEmpty () const |
(从 6.10 起)
QJsonObject::key_value_iterator
|
keyValueBegin () |
(从 6.10 起)
QJsonObject::const_key_value_iterator
|
keyValueBegin () const |
(从 6.10 起)
QJsonObject::key_value_iterator
|
keyValueEnd () |
(从 6.10 起)
QJsonObject::const_key_value_iterator
|
keyValueEnd () const |
| QStringList | keys () const |
| qsizetype | length () const |
| void | remove (const QString & key ) |
| void | remove (QLatin1StringView key ) |
| void | remove (QStringView key ) |
| qsizetype | size () const |
| void | swap (QJsonObject & other ) |
| QJsonValue | take (const QString & key ) |
| QJsonValue | take (QLatin1StringView key ) |
| QJsonValue | take (QStringView key ) |
| QVariantHash | toVariantHash () const |
| QVariantMap | toVariantMap () const |
| QJsonValue | value (const QString & key ) const |
| QJsonValue | value (QLatin1StringView key ) const |
| QJsonValue | value (QStringView key ) const |
| QJsonObject & | operator= (QJsonObject && other ) |
| QJsonObject & | operator= (const QJsonObject & other ) |
| QJsonValueRef | operator[] (const QString & key ) |
| QJsonValue | operator[] (const QString & key ) const |
| QJsonValueRef | operator[] (QLatin1StringView key ) |
| QJsonValueRef | operator[] (QStringView key ) |
| QJsonValue | operator[] (QLatin1StringView key ) const |
| QJsonValue | operator[] (QStringView key ) const |
| QJsonObject | fromVariantHash (const QVariantHash & hash ) |
| QJsonObject | fromVariantMap (const QVariantMap & map ) |
| bool | operator!= (const QJsonObject & lhs , const QJsonObject & rhs ) |
| bool | operator== (const QJsonObject & lhs , const QJsonObject & rhs ) |
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 保存和加载游戏 .
Qt 样式同义词 QJsonObject::const_iterator .
Qt 样式同义词 QJsonObject::iterator .
[since 6.10]
QJsonObject::
const_key_value_iterator
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.
This typedef was introduced in Qt 6.10.
另请参阅 QKeyValueIterator .
typedef 对于 QString . Provided for STL compatibility.
[since 6.10]
QJsonObject::
key_value_iterator
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.
This typedef was introduced in Qt 6.10.
另请参阅 QKeyValueIterator .
typedef 对于 QJsonValue . Provided for STL compatibility.
Typedef for qsizetype. Provided for STL compatibility.
[since 6.10]
auto
QJsonObject::
asKeyValueRange
() &
[since 6.10]
auto
QJsonObject::
asKeyValueRange
() &&
[since 6.10]
auto
QJsonObject::
asKeyValueRange
() const &&
[since 6.10]
auto
QJsonObject::
asKeyValueRange
() const &
Returns a range object that allows iteration over this object as key/value pairs. For instance, this range object can be used in a range-based for loop, in combination with a structured binding declaration:
QJsonObject obj{ { "something", "is" }, { "in", "this" }, { "object", 42 }, }; for (auto [key, value] : obj.asKeyValueRange()) { qDebug() << key << "->" << value; if (key == "object") value = "!"; // modify the object at this key } qDebug() << obj["object"]; // QJsonValue(string, "!")
Note that the value obtained this way is a reference into the one in the object. Specifically, mutating the value will modify the object itself.
When calling this method on rvalues (e.g. on a temporary created in the inializer of a ranged for-loop), the object will be captured in this range.
These functions were introduced in Qt 6.10.
另请参阅 QKeyValueIterator .
构造空的 JSON 对象。
另请参阅 isEmpty ().
Constructs a QJsonObject instance initialized from args initialization list. For example:
QJsonObject object { {"property1", 1}, {"property2", 2} };
[noexcept]
QJsonObject::
QJsonObject
(const
QJsonObject
&
other
)
创建副本为 other .
Since QJsonObject is implicitly shared, the copy is shallow as long as the object does not get modified.
[noexcept]
QJsonObject::
QJsonObject
(
QJsonObject
&&
other
)
移动构造 QJsonObject,从 other .
[noexcept]
QJsonObject::
~QJsonObject
()
销毁对象。
返回 STL 样式迭代器 pointing to the first item in the object.
另请参阅 constBegin () 和 end ().
这是重载函数。
返回常量 STL 样式迭代器 pointing to the first item in the object.
返回常量 STL 样式迭代器 pointing to the imaginary item after the last item in the object.
另请参阅 constBegin () 和 end ().
Returns a const iterator pointing to the item with key key in the map.
If the map contains no item with key key ,函数返回 constEnd ().
这是重载函数。
这是重载函数。
[since 6.10]
QJsonObject::const_key_value_iterator
QJsonObject::
constKeyValueBegin
() const
返回常量 STL 样式迭代器 pointing to the first entry in the object.
该函数在 Qt 6.10 引入。
另请参阅 keyValueBegin ().
[since 6.10]
QJsonObject::const_key_value_iterator
QJsonObject::
constKeyValueEnd
() const
返回常量 STL 样式迭代器 pointing to the imaginary entry after the last entry in the ibject.
该函数在 Qt 6.10 引入。
另请参阅 constKeyValueBegin ().
返回
true
if the object contains key
key
.
另请参阅 insert (), remove (),和 take ().
这是重载函数。
这是重载函数。
如同 size ().
此函数为兼容 STL (标准模板库) 提供。它相当于
isEmpty
(), returning
true
if the object is empty; otherwise returning
false
.
返回 STL 样式迭代器 pointing to the imaginary item after the last item in the object.
这是重载函数。
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 ().
Returns an iterator pointing to the item with key key in the map.
If the map contains no item with key key ,函数返回 end ().
这是重载函数。
这是重载函数。
这是重载函数。
这是重载函数。
这是重载函数。
[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 () 了解更多信息。
另请参阅 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 ().
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 ().
这是重载函数。
这是重载函数。
返回
true
if the object is empty. This is the same as
size
() == 0.
另请参阅 size ().
[since 6.10]
QJsonObject::key_value_iterator
QJsonObject::
keyValueBegin
()
返回 STL 样式迭代器 pointing to the first entry in the object.
该函数在 Qt 6.10 引入。
另请参阅 keyValueEnd ().
[since 6.10]
QJsonObject::const_key_value_iterator
QJsonObject::
keyValueBegin
() const
返回常量 STL 样式迭代器 pointing to the first entry in the object.
该函数在 Qt 6.10 引入。
另请参阅 keyValueEnd ().
[since 6.10]
QJsonObject::key_value_iterator
QJsonObject::
keyValueEnd
()
返回 STL 样式迭代器 pointing to the imaginary entry after the last entry in the object.
该函数在 Qt 6.10 引入。
另请参阅 keyValueBegin ().
[since 6.10]
QJsonObject::const_key_value_iterator
QJsonObject::
keyValueEnd
() const
返回常量 STL 样式迭代器 pointing to the imaginary entry after the last entry in the object.
该函数在 Qt 6.10 引入。
另请参阅 keyValueBegin ().
返回在此对象中的所有键列表。
The list is sorted alphabetically.
如同 size ().
移除 key 从对象。
这是重载函数。
这是重载函数。
Returns the number of (key, value) pairs stored in the object.
[noexcept]
void
QJsonObject::
swap
(
QJsonObject
&
other
)
Swaps this object with other 。此操作很快且从不失败。
移除 key 从对象。
返回 QJsonValue containing the value referenced by key 。若 key was not contained in the object, the returned QJsonValue is QJsonValue::Undefined .
另请参阅 insert (), remove (),和 QJsonValue .
这是重载函数。
这是重载函数。
把此对象转换成 QVariantHash .
返回创建的哈希。
另请参阅 toVariantMap ().
把此对象转换成 QVariantMap .
返回创建的映射。
另请参阅 toVariantHash ().
返回 QJsonValue 表示值为键 key .
返回的 QJsonValue is QJsonValue::Undefined 若键不存在。
另请参阅 QJsonValue and QJsonValue::isUndefined ().
这是重载函数。
这是重载函数。
[noexcept]
QJsonObject
&QJsonObject::
operator=
(
QJsonObject
&&
other
)
移动赋值 other 到此对象。
[noexcept]
QJsonObject
&QJsonObject::
operator=
(const
QJsonObject
&
other
)
赋值 other 到此对象。
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 表示值为键 key .
This does the same as value ().
返回的 QJsonValue is QJsonValue::Undefined 若键不存在。
另请参阅 value (), QJsonValue ,和 QJsonValue::isUndefined ().
这是重载函数。
这是重载函数。
这是重载函数。
这是重载函数。
[noexcept]
bool
operator!=
(const
QJsonObject
&
lhs
, const
QJsonObject
&
rhs
)
返回
true
if
lhs
object is not equal to
rhs
,
false
否则。
[noexcept]
bool
operator==
(const
QJsonObject
&
lhs
, const
QJsonObject
&
rhs
)
返回
true
if
lhs
对象等于
rhs
,
false
否则。