QJsonValueclass encapsulates a value in JSON. 更多 …
def
__eq__
(other)
def
__ne__
(other)
def
isArray
()
def
isBool
()
def
isDouble
()
def
isNull
()
def
isObject
()
def
isString
()
def
isUndefined
()
def
operator[]
(i)
def
operator[]
(key)
def
swap
(other)
def
toArray
()
def
toArray
(defaultValue)
def
toBool
([defaultValue=false])
def
toDouble
([defaultValue=0])
def
toInt
([defaultValue=0])
def
toObject
()
def
toObject
(defaultValue)
def
toString
()
def
toString
(defaultValue)
def
toVariant
()
def
type
()
def
fromVariant
(variant)
A value in JSON can be one of 6 basic types:
JSON 是结构化数据存储格式。它有 6 种基本数据类型:
bool
Booldouble
Doublestring
字符串array
数组object
Objectnull
NullA value can represent any of the above data types. In addition,
QJsonValuehas one special flag to represent undefined values. This can be queried withisUndefined().The type of the value can be queried with
type()or accessors likeisBool(),isString(), and so on. Likewise, the value can be converted to the type stored in it using thetoBool(),toString()and so on.Values are strictly typed internally and contrary to
QVariantwill not attempt to do any implicit type conversions. This implies that converting to a type that is not stored in the value will return a default constructed return value.
QJsonValueRefis a helper class forQJsonArrayandQJsonObject. When you get an object of typeQJsonValueRef, you can use it as if it were a reference to aQJsonValue. If you assign to it, the assignment will apply to the element in theQJsonArrayorQJsonObjectfrom which you got the reference.The following methods return
QJsonValueRef:
QJsonArray::operator[](int i)
QJsonObject::operator[](constQString& key) const另请参阅
在 Qt 中支持 JSON JSON 保存游戏范例
QJsonValue
(
[
arg__1=Null
]
)
¶
QJsonValue(b)
QJsonValue(a)
QJsonValue(o)
QJsonValue(other)
QJsonValue(s)
QJsonValue(s)
QJsonValue(n)
QJsonValue(n)
QJsonValue(v)
- param arg__1
Type- param n
double- param o
QJsonObject- param other
- param a
- param b
bool- param s
unicode
- param v
qint64
创建
QJsonValue
of type
type
.
The default is to create a Null value.
Creates a value of type Bool, with value
b
.
Creates a value of type String with value
s
, assuming UTF-8 encoding of the input.
You can disable this constructor by defining
QT_NO_CAST_FROM_ASCII
when you compile your applications.
Creates a value of type Double, with value
v
.
这是重载函数。
Creates a value of type Double, with value
v
.
这是重载函数。
Creates a value of type Double, with value
v
. NOTE: the integer limits for IEEE 754 double precision data is 2^53 (-9007199254740992 to +9007199254740992). If you pass in values outside this range expect a loss of precision to occur.
PySide2.QtCore.QJsonValue.
Type
¶
This enum describes the type of the JSON value.
|
常量 |
描述 |
|---|---|
|
QJsonValue.Null |
A Null value |
|
QJsonValue.Bool |
A boolean value. Use
|
|
QJsonValue.Double |
A double. Use
|
|
QJsonValue.String |
A string. Use
|
|
QJsonValue.Array |
An array. Use
|
|
QJsonValue.Object |
An object. Use
|
|
QJsonValue.Undefined |
The value is undefined. This is usually returned as an error condition, when trying to read an out of bounds value in an array or a non existent key in an object. |
PySide2.QtCore.QJsonValue.
fromVariant
(
variant
)
¶
variant – object
转换
variant
到
QJsonValue
and returns it.
The conversion will convert
QVariant
types as follows:
|
QJsonValue::Map. See
|
For all other
QVariant
types a conversion to a
QString
will be attempted. If the returned string is empty, a Null
QJsonValue
will be stored, otherwise a String value using the returned
QString
.
另请参阅
PySide2.QtCore.QJsonValue.
isArray
(
)
¶
bool
返回
true
if the value contains an array.
另请参阅
PySide2.QtCore.QJsonValue.
isBool
(
)
¶
bool
返回
true
if the value contains a boolean.
另请参阅
PySide2.QtCore.QJsonValue.
isDouble
(
)
¶
bool
返回
true
if the value contains a double.
另请参阅
PySide2.QtCore.QJsonValue.
isNull
(
)
¶
bool
返回
true
if the value is null.
PySide2.QtCore.QJsonValue.
isObject
(
)
¶
bool
返回
true
if the value contains an object.
另请参阅
PySide2.QtCore.QJsonValue.
isString
(
)
¶
bool
返回
true
if the value contains a string.
另请参阅
PySide2.QtCore.QJsonValue.
isUndefined
(
)
¶
bool
返回
true
if the value is undefined. This can happen in certain error cases as e.g. accessing a non existing key in a
QJsonObject
.
PySide2.QtCore.QJsonValue.
__ne__
(
other
)
¶
other
–
QJsonValue
bool
返回
true
if the value is not equal to
other
.
PySide2.QtCore.QJsonValue.
__eq__
(
other
)
¶
other
–
QJsonValue
bool
返回
true
if the value is equal to
other
.
PySide2.QtCore.QJsonValue.operator[](key)
key – unicode
PySide2.QtCore.QJsonValue.operator[](i)
i
–
int
返回
QJsonValue
representing the value for index
i
.
相当于调用
toArray()
.at(i).
返回的
QJsonValue
is
Undefined
, if
i
is out of bounds, or if
isArray()
is false.
PySide2.QtCore.QJsonValue.
swap
(
other
)
¶
other
–
QJsonValue
Swaps the value
other
with this. This operation is very fast and never fails.
PySide2.QtCore.QJsonValue.
toArray
(
)
¶
这是重载函数。
Converts the value to an array and returns it.
若
type()
is not Array, a
QJsonArray()
将被返回。
PySide2.QtCore.QJsonValue.
toArray
(
defaultValue
)
¶
defaultValue
–
QJsonArray
Converts the value to an array and returns it.
若
type()
is not Array, the
defaultValue
将被返回。
PySide2.QtCore.QJsonValue.
toBool
(
[
defaultValue=false
]
)
¶
defaultValue
–
bool
bool
Converts the value to a bool and returns it.
若
type()
is not bool, the
defaultValue
将被返回。
PySide2.QtCore.QJsonValue.
toDouble
(
[
defaultValue=0
]
)
¶
defaultValue
–
double
double
Converts the value to a double and returns it.
若
type()
is not Double, the
defaultValue
将被返回。
PySide2.QtCore.QJsonValue.
toInt
(
[
defaultValue=0
]
)
¶
defaultValue
–
int
int
Converts the value to an int and returns it.
若
type()
is not Double or the value is not a whole number, the
defaultValue
将被返回。
PySide2.QtCore.QJsonValue.
toObject
(
)
¶
QJsonObject
这是重载函数。
Converts the value to an object and returns it.
若
type()
is not Object, the
QJsonObject()
将被返回。
PySide2.QtCore.QJsonValue.
toObject
(
defaultValue
)
¶
defaultValue
–
QJsonObject
QJsonObject
Converts the value to an object and returns it.
若
type()
is not Object, the
defaultValue
将被返回。
PySide2.QtCore.QJsonValue.
toString
(
)
¶
unicode
Converts the value to a
QString
and returns it.
若
type()
is not String, a null
QString
将被返回。
另请参阅
isNull()
PySide2.QtCore.QJsonValue.
toString
(
defaultValue
)
¶
defaultValue – unicode
unicode
Converts the value to a
QString
and returns it.
若
type()
is not String, the
defaultValue
将被返回。
PySide2.QtCore.QJsonValue.
toVariant
(
)
¶
object
Converts the value to a
QVariant()
.
QJsonValue
types will be converted as follows:
Null
Nullptr
另请参阅