Qt QJson组装数据Sig传递
创始人
2025-01-07 21:06:39
0

有时候界面输入的值,不想创建结构体,那么直接用QString类型传输,更便捷方便,速度更快

QJson是你选择的一种方式

组合:

#include  #include  #include  #include  #include   int main(int argc, char *argv[]) {     QCoreApplication a(argc, argv);      // 创建JSON对象     QJsonObject jsonObject;     jsonObject["name"] = "John Doe";     jsonObject["age"] = 30;      // 创建JSON数组     QJsonArray jsonArray;     jsonArray.append("apple");     jsonArray.append("banana");     jsonArray.append("cherry");      // 将数组添加到对象中     jsonObject["fruits"] = jsonArray;      // 创建JSON文档     QJsonDocument jsonDoc(jsonObject);      // 将JSON文档转换为字符串     QString jsonString = jsonDoc.toJson(QJsonDocument::Indented);     qDebug() << "JSON Data:" << jsonString;      return a.exec(); } 

解析:

#include  #include  #include  #include  #include   int main(int argc, char *argv[]) {     QCoreApplication a(argc, argv);      // JSON字符串     QString jsonString = R"(     {         "name": "John Doe",         "age": 30,         "fruits": ["apple", "banana", "cherry"]     })";      // 将JSON字符串解析为JSON文档     QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonString.toUtf8());      // 检查解析是否成功     if (jsonDoc.isNull() || !jsonDoc.isObject()) {         qWarning() << "Failed to parse JSON";         return -1;     }      // 获取JSON对象     QJsonObject jsonObject = jsonDoc.object();      // 访问数据     QString name = jsonObject["name"].toString();     int age = jsonObject["age"].toInt();     QJsonArray fruitsArray = jsonObject["fruits"].toArray();      qDebug() << "Name:" << name;     qDebug() << "Age:" << age;     qDebug() << "Fruits:";      for (const QJsonValue &value : fruitsArray) {         qDebug() << " -" << value.toString();     }      return a.exec(); } 

AI生成,有需求可以联系我

相关内容

热门资讯

透视法门!hhpoker哪个俱... 透视法门!hhpoker哪个俱乐部靠谱,hhpoker买挂(透视)都是有脚本app(哔哩哔哩)1、透...
透视技法!pokermaste... 透视技法!pokermaster修改器,菠萝德普辅助器免费版在哪里(透视)确实是有挂(哔哩哔哩)1、...
透视手段!wepokerplu... 透视手段!wepokerplus透视脚本免费,wepoker私人局透视插件(透视)切实真的有透视挂(...
透视演示!wepoker公共底... 透视演示!wepoker公共底牌,hhpoker一直输有挂吗(透视)确实真的是有挂(哔哩哔哩)1.h...
透视妙计!德扑之心免费透视,德... 透视妙计!德扑之心免费透视,德普之星透视辅助(透视)真是是有脚本app(哔哩哔哩)德扑之心免费透视脚...
透视办法!hhpoker德州有... 透视办法!hhpoker德州有挂吗,hhpoker有辅助吗(透视)果然是有挂(哔哩哔哩)hhpoke...
透视学习!德普之星私人局辅助免... 透视学习!德普之星私人局辅助免费,德普软件(透视)都是真的是有透视软件(哔哩哔哩)德普之星私人局辅助...
透视教程书!aapoker怎么... 透视教程书!aapoker怎么设置抽水,佛手在线大菠萝辅助(透视)竟然真的是有挂(哔哩哔哩)1、这是...
透视阶段!hhpkoer辅助挂... 透视阶段!hhpkoer辅助挂是真的吗,hhpoker辅助软件(透视)好像真的是有脚本方法(哔哩哔哩...
透视烘培!wepoker轻量版... 透视烘培!wepoker轻量版有透视吗,佛手在线大菠萝为什么都输(透视)确实有挂(哔哩哔哩)亲,关键...