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生成,有需求可以联系我

相关内容

热门资讯

透视能赢"wepok... 透视能赢"wepoker私人局俱乐部辅助(底牌透视脚本)wepoker软件靠谱么"都是有挂;wepo...
透视ai!wpk俱乐部是真的吗... 透视ai!wpk俱乐部是真的吗,(wPk真的有挂)辅助器(本来有挂)1、wpk俱乐部是真的吗系统规律...
透视系统!wepoker手机版... 透视系统!wepoker手机版透视脚本,(WePoKer方法)都是是真的有挂(详细黑侠破解)亲,关键...
透视挂透视!wpk俱乐部辅助器... 透视挂透视!wpk俱乐部辅助器,(WPk插件)插件辅助(一直是有挂)1、wpk俱乐部辅助器ai机器人...
透视新版"wepok... 透视新版"wepoker透视脚本免费使用视频(底牌透视脚本)we-poker有人玩吗"其实存在有挂;...
透视脚本!aapoker透视脚... 透视脚本!aapoker透视脚本,aapoker辅助软件合法吗,技巧教程(好像是有挂)1、aapok...
透视软件!淘宝买wepoker... 透视软件!淘宝买wepoker透视有用吗,wepoker私人局透视教程(透视果然是有挂);1)淘宝买...
透视辅助!wpk俱乐部是做什么... 透视辅助!wpk俱乐部是做什么的,(wpK透视)其实有挂(详细辅助);1、下载好wpk俱乐部是做什么...
透视ai代打!wepoker作... 透视ai代打!wepoker作弊辅助(WePoKer辅助器)破解辅助插件(真是存在有挂)1、不需要A...
透视脚本!aapoker ai... 透视脚本!aapoker ai插件,aapoker怎么提高中牌率,黑科技教程(都是真的有挂)1、实时...