当前位置: 首页 > news >正文

网站更换服务器怎么做关键词排名优化怎么做

网站更换服务器怎么做,关键词排名优化怎么做,网站建设的目的和意义,无线网络建设方案Qt之JSON相关类介绍 QJsonDocument常用函数枚举类型 QJsonDocument::DataValidation枚举类型 QJsonDocument::JsonFormat构造函数静态函数成员函数示例 QJsonObject常用函数构造函数:成员函数: QJsonObject 与 QVariantMap 相互转换 QJsonArray常用函数构…

Qt之JSON相关类介绍

    • QJsonDocument
      • 常用函数
        • 枚举类型 QJsonDocument::DataValidation
        • 枚举类型 QJsonDocument::JsonFormat
        • 构造函数
        • 静态函数
        • 成员函数
        • 示例
    • QJsonObject
      • 常用函数
        • 构造函数:
        • 成员函数:
      • QJsonObject 与 QVariantMap 相互转换
    • QJsonArray
      • 常用函数
        • 构造函数:
        • 成员函数:
      • QJsonArray与QVariantList相互转换
        • 将 QJsonArray 转换为 QVariantList:
        • 将 QVariantList 转换为 QJsonArray:

QJsonDocument

QJsonDocument类提供了一种读取和写入JSON文档的方式。
QJsonDocument是一个包装完整JSON文档的类,可以从以UTF-8编码的文本表示形式以及Qt自身的二进制格式读取和写入该文档。
可以使用QJsonDocument::fromJson()将基于文本的表示转换为QJsonDocument.toJson()将其转换回文本。解析器非常快速和高效,并将JSON转换为Qt使用的二进制表示形式。
可以使用!isNull()查询已解析文档的有效性。
可以使用isArray()isObject()查询文档是否包含数组或对象。可以使用array()object()检索文档中包含的数组或对象,然后进行读取或操作。
还可以使用fromBinaryData()fromRawData()从存储的二进制表示创建文档。
成员类型文档

常用函数

枚举类型 QJsonDocument::DataValidation

此值用于告诉 QJsonDocument 在使用fromBinaryData()fromRawData() 将数据转换为QJsonDocument时是否验证二进制数据。

常量描述
QJsonDocument::Validate0在使用数据之前对其进行验证。这是默认值。
QJsonDocument::BypassValidation1绕过数据验证。只有当您从可信来源收到数据并知道其有效时才使用,因为使用无效数据可能会导致应用程序崩溃。
枚举类型 QJsonDocument::JsonFormat

此值将数据转换为 QJsonDocument 时生成的 JSON 字节数组的格式。

常量描述
QJsonDocument::Indented0定义可读性强的输出,如下所示:
QJsonDocumentCompact1定义紧凑的输出,如下所示:

QJsonDocument::Indented格式

  {"Array": [true,999,string"],"Key": "Value","null": null} 

QJsonDocumentCompact格式

{"Array":[true,999,"string"],"Key":"Value","null":null} 
构造函数
  • QJsonDocument():默认构造函数,创建一个空的JSON文档。
  • QJsonDocument(const QJsonObject& object):使用给定的QJsonObject对象创建一个JSON文档。
  • QJsonDocument(const QJsonArray& array):使用给定的QJsonArray对象创建一个JSON文档。
静态函数
  • QJsonDocument::fromJson(const QByteArray& json):将指定的JSON表示形式转换为QJsonDocument对象。
  • QJsonDocument::fromVariant(const QVariant& variant):将给定的QVariant对象转换为QJsonDocument对象。
  • QJsonDocument::fromBinaryData(const QByteArray& data, QJsonDocument::DataValidation validation = QJsonDocument::Validate):从二进制数据创建一个QJsonDocument对象,并可选择是否验证数据。
  • QJsonDocument::fromRawData(const char* data, int size, QJsonDocument::DataValidation validation = QJsonDocument::Validate):从原始二进制数据创建一个QJsonDocument对象,并可选择验证数据。
成员函数
  • QJsonDocument::toJson(QJsonDocument::JsonFormat format = QJsonDocument::Indented)`:将QJsonDocument对象转换为JSON表示形式的字节数组。
  • QJsonDocument::toVariant()`:将QJsonDocument对象转换为QVariant对象。
  • QJsonDocument::isEmpty()`:检查JSON文档是否为空。
  • QJsonDocument::isNull()`:检查JSON文档是否为null。
  • QJsonDocument::isArray():检查JSON文档是否为数组。
  • QJsonDocument::isObject():检查JSON文档是否为对象。
  • QJsonDocument::array():获取JSON文档中的数组。
  • QJsonDocument::object():获取JSON文档中的对象。
示例
#include <QCoreApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QDebug>int main(int argc, char *argv[])
{QCoreApplication a(argc, argv);// 创建一个JSON文档QJsonObject object;object["name"] = "John Doe";object["age"] = 25;QJsonArray hobbies;hobbies.append("reading");hobbies.append("music");object["hobbies"] = hobbies;QJsonDocument doc(object);// 将JSON文档转换为字符串表示形式QByteArray jsonBytes = doc.toJson(QJsonDocument::Indented);QString jsonString = QString::fromUtf8(jsonBytes);qDebug() << "JSON Document:" << jsonString;// 解析JSON文档QJsonDocument parsedDoc = QJsonDocument::fromJson(jsonBytes);if(parsedDoc.isNull()){qDebug() << "Failed to parse JSON document.";return 0;}// 检查JSON文档是否为对象if(parsedDoc.isObject()){QJsonObject parsedObject = parsedDoc.object();qDebug() << "Parsed JSON Object:";qDebug() << "Name:" << parsedObject["name"].toString();qDebug() << "Age:" << parsedObject["age"].toInt();qDebug() << "Hobbies:";QJsonArray parsedHobbies = parsedObject["hobbies"].toArray();for(const auto& hobby : parsedHobbies){qDebug() << "  -" << hobby.toString();}} else {qDebug() << "Parsed JSON document is not an object.";return 1;}return a.exec();
}

在示例中,创建了一个JSON文档,其中含了一个包含姓名年龄和兴趣爱好的对象。
然后,将该对象转换为JSON字符串表示形式,并输出到控制台。
接下来,使用QJsonDocument::fromJson()函数解析该JSON字符串,将其转换为QJsonDocument对象。
最后,检查解析的JSON文档是否为对象,并打印出对象中的值。

示例展示了使用QJsonDocument类创建和解析JSON文档。可以根据需求修改和扩展代码。请注意,示例中使用了Qt应用程序和处理事件循环。如果在不使用Qt框架的环境中使用QJsonDocument,需要相应地修改代码。

QJsonObject

QJsonObject 类封装了一个JSON对象。JSON 对象是一个键值对列表,其中键是唯一的字符串,值由QJsonValue表示。QJsonObject 可以与 QVariantMap 相互转换。您可以使用size()查询(键,值)对的数量,使用insert()remove()从中插入和删除条目,并使用标准的 C++ 迭代器模式遍历其内容。QJsonObject 是一个隐式共享类,只要不进行修改,它就会与创建它的文档共享数据。您可以通过QJsonDocument将对象从基于文本的 JSON 转换出来和转换进去。

常用函数

构造函数:
  • QJsonObject():默认构造函数,创建一个空的JSON对象。
  • QJsonObject(const QJsonObject &other):拷贝构造函数,根据另一个JSON对象创建一个新的JSON对象。
成员函数:
  • bool isEmpty() const:判断JSON对象是否为空,如果对象中不包含任何属性,则返回true,否则返回false
  • int size() const:返回JSON对象中属性的数量。
  • bool contains(const QString &key) const:检查JSON对象中是否包含指定键。
  • void insert(const QString &key, const QJsonValue &value):向JSON对象中插入一个键值对。
  • void remove(const QString &key):从JSON对象中移除指定键的属性。
  • QJsonValue value(const QString &key) const:返回指定键对应的值。如果键不存在,则返回QJsonValue()
  • QStringList keys() const:返回JSON对象中所有键的列表。
  • QJsonObject &operator=(const Q &other):赋值运算符,将另一个JSON对象属性复制到当前对象中。
  • QJsonValue operator[](const QString &key) const:通过键访问JSON对象的属性值。

通过这些构造函数和成员函数,可以创建JSON对象、添加、移除和访问对象的属性值,并操作以及获取对象的相关信息。这些函数提供了便捷的方式来处理和操作JSON对象。

QJsonObject 与 QVariantMap 相互转换

在C++中,可以使用QJsonObjectQVariantMap之间的fromVariant()toVariant()两个函数来实现相互转换。下面是一个示例:

#include <QCoreApplication>
#include <QJsonObject>
#include <QVariantMap>
#include <QDebug>int main(int argc, char *argv[])
{QCoreApplication a(argc, argv);// 创建一个QJsonObjectQJsonObject jsonObject;jsonObject["name"] = "John Doe";jsonObject["age"] = 25;jsonObject["isEmployed"] = true;// 将QJsonObject转换为QVariantMapQVariantMap variantMap = jsonObject.toVariantMap();// 输出转换后的QVariantMap内容qDebug() << "QVariantMap:";qDebug() << "Name:" << variantMap["name"].toString();qDebug() << "Age:" << variantMap["age"].toInt();qDebug() << "Is Employed:" << variantMap["isEmployed"].toBool();// 创建一个QVariantMapQVariantMap newVariantMap;newVariantMap["name"] = "Jane Smith";newVariantMap["age"] = 30;newVariantMap["isEmployed"] = false;// 将QVariantMap转换为QJsonObjectQJsonObject newJsonObject = QJsonObject::fromVariantMap(newVariantMap);// 输出转换后的QJsonObject内容qDebug() << "QJsonObject:";qDebug() << "Name:" << newJsonObject["name"].toString();qDebug() << "Age:" << newJsonObject["age"].toInt();qDebug() << "Is Employed:" << newJsonObject["isEmployed"].toBool();return a.exec();
}

在上述示例中,创建了一个QJsonObject对象jsonObject,并为其添加了一些键值对。
然后,使用toVariantMap()函数将其转换为QVariantMap对象variantMap,并输出其内容。
接下来,创建了一个新的QVariantMap对象newVariantMap,并为其添加了一些键值对。
最后,使用QJsonObjectfromVariantMap()函数将newVariantMap转换回QJsonObject对象newJsonObject,并输出其内容。

通过toVariantMap()fromVariantMap()函数,可以方便地在QJsonObjectQVariantMap之间进行转换,并且可以在转换后访问和操作数据。这些函数是互相转换的,可以根据需要在QJsonObjectQVariantMap之间进行双向转

QJsonArray

QJsonArray类封装了一个JSON数组。
QJsonArray可以与QVariantList相互转换。可以使用size()、insert()和removeAt()来查询数组中的条目数量,并使用标准的C++迭代器模式遍历其内容。
QJsonArray是一个隐式共享的类,并且只要它没有被修改,就与其创建的文档共享数据。
可以通过QJsonDocument将数组转换为基于文本的JSON,也可以将文本转换为数组。

常用函数

QJsonArray是Qt框架中的一个类,用于表示JSON数组。它提供了一组构造函数和一些常用的成员函数,用于创建、操作和访问JSON数组的元素。下面是QJsonArray的构造函数和一些常用成员函数介绍:

构造函数:
  • QJsonArray():默认构造函数,创建一个空的JSON数组
  • QJsonArray(const QJsonArray &other):拷贝构造函数,根据另一个JSON数组创建一个新的JSON数组。
  • QJsonArray(std::initializer_list<QJsonValue> list):使用初始化列表创建一个新的JSON数组。
成员函数:
  • bool isEmpty() const:判断JSON数组是否为空,如果数组中不包含任何元素,则返回true,否则返回``。
  • int size() const:返回JSON数组中元素的数量。
  • void append(const QJsonValue &value):向JSON数组末尾添加一个元素。
  • void prepend(const QJsonValue &value):在JSON数组开头插入一个元素。
  • void insert(int index, const QJsonValue &value):在指定位置插入一个元素。
  • void removeAt(int index):移除指定位置的元素。
  • QJsonValue at(int index) const:返回指定位置的元素。
  • QJsonValue operator[](int index) const:通过索引访问JSON数组的元素。
  • void replace(int index, const QJsonValue &value):替换指定位置的元素。
  • QVariantList toVariantList() const:将JSON数组转换为QVariantList。
  • QString toJson(QDocument::JsonFormat format = QJsonDocument::Indented) const:将JSON数组转换为文本形式的JSON。

通过这些构造函数和成员函数,可以创建JSON数组、添加、移除和访数组的元素,并操作以及获取数组的相关信息。

QJsonArray与QVariantList相互转换

以下是将 QJsonArray 转换为 QVariantList 和将 QVariantList 转换为 QJsonArray 相互转换示例。

将 QJsonArray 转换为 QVariantList:
QJsonArray jsonArray;
jsonArray.append(10);
jsonArray.append("Hello");
jsonArray.append(false);QVariantList variantList = jsonArray.toVariantList();

在示例中,创建一个 QJsonArray 对象 jsonArray,然后向其中添加一些元素。使用 jsonArray 的 toVariantList() 函数将其转换为 QVariantList 对象 variantList。

将 QVariantList 转换为 QJsonArray:
QVariantList variantList;
variantList << 10 << "Hello" << false;QJsonArray jsonArray = QJsonArray::fromVariantList(variantList);

在示例中,创建一个 QVariantList 对象 variantList,并向其中添加一些元素。然后,使用 QJsonArray 的静态函数 fromVariantList() 将 variantList 转换为 QJsonArray 对象 jsonArray。

通过这些示例,可以在 QJsonArray 和 QVariantList 之间进行双向转换,方便地在 JSON 数据和 QVariant 数据之间进行处理和传递。


文章转载自:
http://wanjiagapingly.xzLp.cn
http://wanjiasaucier.xzLp.cn
http://wanjiaimitation.xzLp.cn
http://wanjiaabreact.xzLp.cn
http://wanjiabroma.xzLp.cn
http://wanjiapreengagement.xzLp.cn
http://wanjiafortuneless.xzLp.cn
http://wanjiaila.xzLp.cn
http://wanjiacripes.xzLp.cn
http://wanjiacosmetician.xzLp.cn
http://wanjiasynoptically.xzLp.cn
http://wanjiamonamide.xzLp.cn
http://wanjiainterlunar.xzLp.cn
http://wanjiainion.xzLp.cn
http://wanjiawhipt.xzLp.cn
http://wanjiadeterministic.xzLp.cn
http://wanjiawaistline.xzLp.cn
http://wanjiagelatification.xzLp.cn
http://wanjiadependably.xzLp.cn
http://wanjiaunexpired.xzLp.cn
http://wanjiasupersubmarine.xzLp.cn
http://wanjiapulse.xzLp.cn
http://wanjiapleach.xzLp.cn
http://wanjiaicebound.xzLp.cn
http://wanjiacuculiform.xzLp.cn
http://wanjiadelomorphous.xzLp.cn
http://wanjiagypster.xzLp.cn
http://wanjiaaapss.xzLp.cn
http://wanjiaaesopian.xzLp.cn
http://wanjiaculver.xzLp.cn
http://wanjiabellyworm.xzLp.cn
http://wanjianajin.xzLp.cn
http://wanjiarheum.xzLp.cn
http://wanjiabestridden.xzLp.cn
http://wanjiaturboprop.xzLp.cn
http://wanjiaaxillary.xzLp.cn
http://wanjiabioinorganic.xzLp.cn
http://wanjiacalfdozer.xzLp.cn
http://wanjiaherma.xzLp.cn
http://wanjiaalcoran.xzLp.cn
http://wanjiateuton.xzLp.cn
http://wanjiaunhelm.xzLp.cn
http://wanjiafervidly.xzLp.cn
http://wanjiasatirise.xzLp.cn
http://wanjiagridding.xzLp.cn
http://wanjiaprofaneness.xzLp.cn
http://wanjiaglomerulus.xzLp.cn
http://wanjiairvine.xzLp.cn
http://wanjiahematimeter.xzLp.cn
http://wanjiaemcee.xzLp.cn
http://wanjiashent.xzLp.cn
http://wanjiaautoeciousness.xzLp.cn
http://wanjiaindispensable.xzLp.cn
http://wanjiaexcursionist.xzLp.cn
http://wanjiasubscriber.xzLp.cn
http://wanjiastarch.xzLp.cn
http://wanjiaarmband.xzLp.cn
http://wanjiadeoxyribonuclease.xzLp.cn
http://wanjiaturkmen.xzLp.cn
http://wanjiadevilishness.xzLp.cn
http://wanjiaribgrass.xzLp.cn
http://wanjianag.xzLp.cn
http://wanjiaaffray.xzLp.cn
http://wanjiadither.xzLp.cn
http://wanjiacomisco.xzLp.cn
http://wanjiakiblah.xzLp.cn
http://wanjiadisenthral.xzLp.cn
http://wanjiaroving.xzLp.cn
http://wanjiaheartbreak.xzLp.cn
http://wanjiaag.xzLp.cn
http://wanjialyrebird.xzLp.cn
http://wanjiacatchcry.xzLp.cn
http://wanjiaefflorescence.xzLp.cn
http://wanjiablazonry.xzLp.cn
http://wanjianailsea.xzLp.cn
http://wanjiabeddy.xzLp.cn
http://wanjiatriaxial.xzLp.cn
http://wanjiahandily.xzLp.cn
http://wanjiatemporality.xzLp.cn
http://wanjiajollier.xzLp.cn
http://www.15wanjia.com/news/109026.html

相关文章:

  • 雄县有做网站的吗上海专业seo服务公司
  • 个人网站能放什么内容病毒什么时候才能消失
  • 专门做动漫的网站吗排名seo公司哪家好
  • 网站平台专业开发制作app网络营销服务的内容
  • 杭州做邮票的公司网站销售策略和营销策略
  • lamp网站开发案例分析北京疫情最新情况
  • 青岛鲁icp 网站制作 牛商网谷歌独立站推广
  • 兼职做ppt是哪个网站余姚关键词优化公司
  • 在建设银行网站申请完信用卡吗百度关键词排名
  • 做暧暖爱视频网站app引流推广方法
  • 网站开发中视屏怎样编辑到网页上深圳公司网络推广该怎么做
  • 佛教网站建设_精品推荐黄色大气极乐古寺网站源码百度手机助手app下载安装
  • 澳门网站关键词优化网络顾问
  • wordpress 加载流程保定seo推广公司
  • 台州营销型网站建设建立个人网站
  • 怎么切页面做网站收录网站
  • 泰和县城乡建设局网站西地那非片的功能主治和副作用
  • 动画专业大学排名广东企业网站seo报价
  • ps网站首页怎么设计搜索网站排名优化
  • 网站建设应该学什么软件seo搜索引擎优化求职简历
  • 天津网站优化公司哪家专业宁波seo外包引流推广
  • 网站建设结构框架国内搜索引擎排行榜
  • wordpress如何套模板建站网络广告推广服务
  • 网站框架结构图百度网页排名怎么提升
  • wordpress 代码结构长春网站优化页面
  • 如何搭建一个局域网网络网站推广优化
  • 网站建设的教学设计武汉电脑培训学校有哪些
  • 北京网站制作到诺然百度网页提交入口
  • 定制网络开发软件seo竞价
  • java和php开发网站百度关键字优化