PySide6.QtCore.QJsonArray¶
- class QJsonArray¶
QJsonArray类封装了一个 JSON 数组。更多…概要¶
方法¶
def
__init__()def
append()def
at()def
contains()def
count()def
empty()def
first()def
insert()def
isEmpty()def
last()def
__ne__()def
__add__()def
__iadd__()def
__lshift__()def
__eq__()def
operator[]()def
pop_back()def
pop_front()def
prepend()def
push_back()def
push_front()def
removeAt()def
removeFirst()def
removeLast()def
replace()def
size()def
swap()def
takeAt()def
toVariantList()
静态函数¶
def
fromStringList()
注意
本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。
详细描述¶
JSON数组是一个值的列表。可以通过插入和移除
QJsonValue来操作这个列表。一个
QJsonArray可以转换为QVariantList,也可以从QVariantList转换而来。你可以使用size()查询条目数量,使用insert()和removeAt()插入和删除条目,并使用标准的C++迭代器模式遍历其内容。QJsonArray是一个隐式共享类,只要它没有被修改,就会与创建它的文档共享数据。您可以通过
QJsonDocument将数组转换为基于文本的JSON,或从基于文本的JSON转换回数组。另请参阅
JSON Support in Qt 保存和加载游戏
- __init__()¶
创建一个空数组。
- __init__(other)
- Parameters:
其他 –
QJsonArray
创建
other的副本。由于
QJsonArray是隐式共享的,只要对象未被修改,复制就是浅拷贝。- append(value)¶
- Parameters:
值 –
QJsonValue
在数组的末尾插入
value。- at(i)¶
- Parameters:
i – 整数
- Return type:
返回一个
QJsonValue,表示索引i的值。返回的
QJsonValue是Undefined,如果i超出范围。- contains(element)¶
- Parameters:
元素 –
QJsonValue- Return type:
布尔
如果数组包含
value的出现,则返回true,否则返回false。另请参阅
- count()¶
- Return type:
整数
与
size()相同。另请参阅
- empty()¶
- Return type:
布尔
此函数为STL兼容性提供。它等同于
isEmpty(),如果数组为空则返回true。- first()¶
- Return type:
返回存储在数组中的第一个值。
与
at(0)相同。另请参阅
- static fromStringList(list)¶
- Parameters:
list – 字符串列表
- Return type:
将字符串列表
list转换为QJsonArray。list中的值将被转换为 JSON 值。- static fromVariantList(list)¶
- Parameters:
list – QVariant 的列表
- Return type:
将变体列表
list转换为QJsonArray。list中的QVariant值将被转换为JSON值。- insert(i, value)¶
- Parameters:
i – 整数
value –
QJsonValue
在数组的索引位置
i插入value。如果i是0,则该值会被添加到数组的开头。如果i是size(),则该值会被添加到数组的末尾。- isEmpty()¶
- Return type:
布尔
如果对象为空,则返回
true。这与size()== 0相同。另请参阅
- last()¶
- Return type:
返回数组中存储的最后一个值。
与
at(size() - 1)相同。另请参阅
- __ne__(rhs)¶
- Parameters:
rhs –
QJsonArray- Return type:
布尔
如果
lhs数组不等于rhs,则返回true,否则返回false。- __ne__(rhs)
- Parameters:
rhs –
QJsonValue- Return type:
布尔
- __add__(v)¶
- Parameters:
v –
QJsonValue- Return type:
返回一个数组,该数组包含此数组中的所有项目,后跟提供的
value。另请参阅
operator+=()- __iadd__(v)¶
- Parameters:
v –
QJsonValue- Return type:
将
value附加到数组中,并返回对数组本身的引用。另请参阅
append()操作符- __lshift__(v)¶
- Parameters:
v –
QJsonValue- Return type:
将
value附加到数组中,并返回对数组本身的引用。另请参阅
operator+=()append()- __eq__(rhs)¶
- Parameters:
rhs –
QJsonArray- Return type:
布尔
如果
lhs数组等于rhs,则返回true,否则返回false。- __eq__(rhs)
- Parameters:
rhs –
QJsonValue- Return type:
布尔
- operator(i)¶
- Parameters:
i – 整数
- Return type:
这是一个重载函数。
与
at()相同。- pop_back()¶
此函数为STL兼容性提供。它等同于
removeLast()。数组不能为空。如果数组可能为空,在调用此函数之前请调用isEmpty()。- pop_front()¶
此函数为STL兼容性提供。它等同于
removeFirst()。数组不能为空。如果数组可能为空,在调用此函数之前请调用isEmpty()。- prepend(value)¶
- Parameters:
值 –
QJsonValue
在数组的开头插入
value。这与
insert(0, value)相同,并将value前置到数组中。- push_back(t)¶
- Parameters:
t –
QJsonValue
此函数为STL兼容性提供。它等同于
append(value),并将value附加到数组中。- push_front(t)¶
- Parameters:
t –
QJsonValue
此函数为STL兼容性提供。它等同于
prepend(value),并将value前置到数组中。- removeAt(i)¶
- Parameters:
i – 整数
移除索引位置
i处的值。i必须是数组中的有效索引位置(即0 <= i < size())。- removeFirst()¶
移除数组中的第一个项目。调用此函数等同于调用
removeAt(0)。数组不能为空。如果数组可能为空,请在调用此函数之前调用isEmpty()。另请参阅
- removeLast()¶
移除数组中的最后一项。调用此函数等同于调用
removeAt(size() - 1)。数组不能为空。如果数组可能为空,请在调用此函数之前调用isEmpty()。另请参阅
- replace(i, value)¶
- Parameters:
i – 整数
value –
QJsonValue
用
value替换索引位置i处的项目。i必须是数组中的有效索引位置(即0 <= i < size())。另请参阅
operator[]()removeAt()- size()¶
- Return type:
整数
返回数组中存储的值的数量。
- swap(other)¶
- Parameters:
其他 –
QJsonArray
将数组
other与此数组交换。此操作非常快速且永远不会失败。- takeAt(i)¶
- Parameters:
i – 整数
- Return type:
移除索引位置
i处的项目并返回它。i必须是数组中的有效索引位置(即0 <= i < size())。如果你不使用返回值,
removeAt()更高效。另请参阅
- toVariantList()¶
- Return type:
.QVariant 列表
将此对象转换为QVariantList。
返回创建的地图。