内容表

上一话题

QJsonParseError

下一话题

QLibraryInfo

QJsonValue

QJsonValue class encapsulates a value in JSON. 更多

Inheritance diagram of PySide2.QtCore.QJsonValue

概要

函数

静态函数

详细描述

A value in JSON can be one of 6 basic types:

JSON 是结构化数据存储格式。它有 6 种基本数据类型:

  • bool Bool

  • double Double

  • string 字符串

  • array 数组

  • object Object

  • null Null

A value can represent any of the above data types. In addition, QJsonValue has one special flag to represent undefined values. This can be queried with isUndefined() .

The type of the value can be queried with type() or accessors like isBool() , isString() , and so on. Likewise, the value can be converted to the type stored in it using the toBool() , toString() and so on.

Values are strictly typed internally and contrary to QVariant will 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.

QJsonValueRef

QJsonValueRef is 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.

The following methods return QJsonValueRef :

  • QJsonArray ::operator[](int i)

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

另请参阅

在 Qt 中支持 JSON JSON 保存游戏范例

class 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

QJsonValue

param a

QJsonArray

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 toBool() to convert to a bool.

QJsonValue.Double

A double. Use toDouble() to convert to a double.

QJsonValue.String

A string. Use toString() to convert to a QString .

QJsonValue.Array

An array. Use toArray() to convert to a QJsonArray .

QJsonValue.Object

An object. Use toObject() to convert to a QJsonObject .

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.

static PySide2.QtCore.QJsonValue. fromVariant ( variant )
参数

variant – object

返回类型

QJsonValue

转换 variant QJsonValue and returns it.

The conversion will convert QVariant types as follows:

QJsonValue::Map. See toJsonValue() for conversion restrictions and the “stringification” of map keys.

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 .

另请参阅

toVariant()

PySide2.QtCore.QJsonValue. isArray ( )
返回类型

bool

返回 true if the value contains an array.

另请参阅

toArray()

PySide2.QtCore.QJsonValue. isBool ( )
返回类型

bool

返回 true if the value contains a boolean.

另请参阅

toBool()

PySide2.QtCore.QJsonValue. isDouble ( )
返回类型

bool

返回 true if the value contains a double.

另请参阅

toDouble()

PySide2.QtCore.QJsonValue. isNull ( )
返回类型

bool

返回 true if the value is null.

PySide2.QtCore.QJsonValue. isObject ( )
返回类型

bool

返回 true if the value contains an object.

另请参阅

toObject()

PySide2.QtCore.QJsonValue. isString ( )
返回类型

bool

返回 true if the value contains a string.

另请参阅

toString()

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

返回类型

QJsonValue

PySide2.QtCore.QJsonValue.operator[](i)
参数

i int

返回类型

QJsonValue

返回 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 ( )
返回类型

QJsonArray

这是重载函数。

Converts the value to an array and returns it.

type() is not Array, a QJsonArray() 将被返回。

PySide2.QtCore.QJsonValue. toArray ( defaultValue )
参数

defaultValue QJsonArray

返回类型

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

另请参阅

fromVariant()

PySide2.QtCore.QJsonValue. type ( )
返回类型

Type

Returns the type of the value.

另请参阅

Type