Qt中QJsonValue类

1. QJsonValue类介绍

Header:	#include <QJsonValue> 
qmake:	QT += core
Since:	Qt 5.0

QJsonValue类封装了JSON中的值。JSON中的值有6种基本类型:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-YbES3V7t-1571912550677)(assets/1571912226251.png)]

value可以是以上任何一种数据类型。另外,QJsonValue有一个特殊的flag来表示未定义类型。可以用isUndefined()来查询。

可以用type()或isBool(),、isString()等来查询value的类型。类似的,可以用toBool()、toString()等将一个value转换成存储在该value内部的类型。

本文福利,费领取Qt开发学习资料包、技术视频,内容包括(C++语言基础,Qt编程入门,QT信号与槽机制,QT界面开发-图像绘制,QT网络,QT数据库编程,QT项目实战,QSS,OpenCV,Quick模块,面试题等等)↓↓↓↓↓↓见下面↓↓文章底部点击费领取↓↓

2. QJsonValue成员方法

QJsonValue(QJsonValue::Type type = Null)
QJsonValue(bool b)
QJsonValue(double n)
QJsonValue(int n)
QJsonValue(qint64 n)
QJsonValue(const QString &s)
QJsonValue(QLatin1String s)
QJsonValue(const char *s)
QJsonValue(const QJsonArray &a)
QJsonValue(const QJsonObject &o)
QJsonValue(const QJsonValue &other)
QJsonValue(QJsonValue &&other)
~QJsonValue()
bool isArray() const
bool isBool() const
bool isDouble() const
bool isNull() const
bool isObject() const
bool isString() const
bool isUndefined() const
void swap(QJsonValue &other)
QJsonArray toArray(const QJsonArray &defaultValue) const
QJsonArray toArray() const
bool toBool(bool defaultValue = false) const
double toDouble(double defaultValue = 0) const
int toInt(int defaultValue = 0) const
QJsonObject toObject(const QJsonObject &defaultValue) const
QJsonObject toObject() const
QString toString() const
QString toString(const QString &defaultValue) const
QVariant toVariant() const
QJsonValue::Type type() const
bool operator!=(const QJsonValue &other) const
QJsonValue &operator=(const QJsonValue &other)
QJsonValue &operator=(QJsonValue &&other)
bool operator==(const QJsonValue &other) const
const QJsonValue operator[](const QString &key) const
const QJsonValue operator[](QLatin1String key) const
const QJsonValue operator[](int i) const

3. QJsonValue成员方法介绍

[static] QJsonValue QJsonValue::fromVariant(const QVariant &variant)
将variant转换为QJsonValue

bool QJsonValue::isArray() const
如果QJsonValue包含一个数组,返回true

bool QJsonValue::isBool() const
如果QJsonValue包含一个bool,返回true

bool QJsonValue::isDouble() const
如果QJsonValue包含一个double,返回true

bool QJsonValue::isNull() const
如果QJsonValue包含一个Null,返回true

bool QJsonValue::isObject() const
如果QJsonValue包含一个object,返回true

bool QJsonValue::isString() const
如果QJsonValue包含一个string,返回true

bool QJsonValue::isUndefined() const
如果QJsonValue包含一个undefined,返回true

QJsonArray QJsonValue::toArray(const QJsonArray &defaultValue) const
将QJsonValue转换为QJsonArray并返回,如果类型不是array,返回默认值defaultValue

QJsonArray QJsonValue::toArray() const
将QJsonValue转换为QJsonArray并返回

bool QJsonValue::toBool(bool defaultValue = false) const
将QJsonValue转换为bool并返回

double QJsonValue::toDouble(double defaultValue = 0) const
将QJsonValue转换为double并返回

int QJsonValue::toInt(int defaultValue = 0) const
将QJsonValue转换为int并返回

QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const
QJsonObject QJsonValue::toObject() const
将QJsonValue转换为QJsonObject并返回

QString QJsonValue::toString(const QString &defaultValue = QString()) const
将QJsonValue转换为QString并返回

Type QJsonValue::type() const
返回QJsonValue的类型

Qt官方参考手册: Qt 5.12–> Qt Core --> C++ Classes --> QJsonValue

本文福利,费领取Qt开发学习资料包、技术视频,内容包括(C++语言基础,Qt编程入门,QT信号与槽机制,QT界面开发-图像绘制,QT网络,QT数据库编程,QT项目实战,QSS,OpenCV,Quick模块,面试题等等)↓↓↓↓↓↓见下面↓↓文章底部点击费领取↓↓

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值