QT 解析JSon字符串
来源:互联网 发布:淘宝手机端图片加链接 编辑:程序博客网 时间:2024/06/06 22:01
解析如下图所示JSON
代码如下图
#include "mainwindow.h"#include <QApplication>#include <QDebug>#include <QJsonDocument>#include <QJsonArray>#include <QJsonObject>#include <QDebug>#include <QObject>bool MakePrtMsg(QJsonObject PrintMsg){ /* 解析传入数据 */ QJsonObject jo = PrintMsg; /* 1.获取数据 */ QString shop_id = jo["shop_id"].toString(); qDebug() << "商户号: " + shop_id; /* 2.获取Json嵌套 */ //QJsonValue value = jo.value("buy_items"); //获取value //QJsonArray buy_items = value.toArray(); //value转换 QJsonArray buy_items = jo.["buy_items"].toArray; for(int i=0; i<buy_items.size(); i++) { QJsonValue value1 = buy_items.at(i); QJsonObject item = value1.toObject(); QString title = item["title"].toString(); qDebug() << "title: " + title; }}int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; QString t = QObject::tr("{") + \ "\"retflag\":\"0\"," + \ "\"TXTString\":" + \ "{" + \ "\"buy_items\":" + \ "[" + \ "{\"title\":\"生鲜1元\"}," + \ "{\"title\":\"生鲜2元\"}" + \ "]" + \ "}," + \ "\"total\":100" + \ "}"; qDebug() << t; QByteArray buf = t.toUtf8(); QJsonDocument jd = QJsonDocument::fromJson(buf); if(jd.isObject()) { QJsonObject jo = jd.object(); /* 打印商品信息 */ //QJsonValue value = jo.value("TXTString"); //QJsonObject PrintMsg = value.toObject(); QJsonObject jo.["TXTString"].toObject(); MakePrtMsg(PrintMsg); } w.show(); return a.exec();}
阅读全文
0 0
- QT 解析JSon字符串
- Qt JSON解析
- Qt 解析json
- QT解析JSON
- Qt之json解析
- Qt json解析
- QT Json解析方法
- Qt的json解析
- Qt 解析Json
- QT 解析JSON
- qt 解析json文件
- qt json解析
- Qt之JSON解析
- QT Json 解析
- flex解析json字符串
- jackson解析 json字符串
- java 解析 json 字符串
- java解析json字符串
- JVM类加载机制
- 如何在windows下打静默安装包
- C#学习笔记
- protocol buffers介绍
- iOS_如何使用xcode 8进行内存泄漏测试
- QT 解析JSon字符串
- 腾讯云-云通信第三方回调接口设计
- warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
- Log4j详解
- Inno setup自定义窗口动态修改配置参数
- Epson工业机器人初体验-02
- xcode8 使用Instruments检测定位并解决iOS内存泄露
- 自考导图|网络经济与企业管理
- github制作你自己的Android studio依赖引用文件