资源简介
qt5中QtCore中开始支持json解析。很方便

代码片段和文件信息
#include
#include ject>
#include
#include
#include
#include
#include
#include
#include
int main(int argc char *argv[])
{
QCoreApplication a(argc argv);
QString str = “{\“name\“:\“xiaotang\“ \“age\“:\“23\“ \“chi\“:[{\“a\“:\“aa\“ \“b\“:\“bb\“} {\“a\“:\“aaa\“ \“b\“:\“bbb\“}]}“;
/*
QFile file(“/home/zhenglq/item/demo/test_json/test.json“);
if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
{
return 0;
}
QByteArray val = file.readAll();
file.close();
*/
QJsonParseError jsonParseError;
QJsonDocument jsonDocument;
jsonDocument = QJsonDocument::fromJson(str.toUtf8()&jsonParseError);
if(jsonDocument.isNull())
{
return 0;
}
if(!jsonDocument.isobject())
{
return 0;
}
int age = 0;
QString name;
QString valuea;
QString valueb;
QJsonobject jsonobject = jsonDocument.object();
name = jsonobject[“name“].toString();
age = jsonobject[“age“].toInt();
//analyze array
QJsonArray chiArray = jsonobject.value(“chi“).toArray();
for(int i = 0; i < chiArray.size(); ++i)
{
valuea = chiArray[i].toobject()[“a“].toString();
valueb = chiArray[i].toobject()[“b“].toString();
}
return a.exec();
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1372 2014-04-22 14:12 test_json\main.cpp
文件 69 2014-04-22 14:17 test_json\readme.txt
文件 24 2014-04-22 14:12 test_json\test.json
文件 293 2014-04-22 14:12 test_json\test_json.pro
文件 18168 2014-04-22 14:12 test_json\test_json.pro.user
目录 0 2014-04-22 14:13 test_json
----------- --------- ---------- ----- ----
19926 6
- 上一篇:Selenium IEDriver
- 下一篇:用maxplus做的存储器电路
相关资源
- QT局域网聊天系统(基于QT5.修改过)
- QT5.5入门与项目实战
- 基于FFmpeg4.0.2的AAC编码器
- mp4_play.zip
- 使用Qt编写的视频监控系统支持Qt4-Q
- Qt 多线程连接数据库——数据库
- 基于Qt5.8+OpenCV3.2的Basler多相机触发开
- 串口调试助手 Qt5版源码
- Qt5的多线程小程序,实现按钮开关线
- Ubuntu16.04中配置Qt5.9.1和OpenCV3.4.0过程
- Qt pdf poppler
- 基于Qt5的串口调试助手
- Qt类关系图
- PyQt5编写的大数据应用-高速公路违章
- QT5.9.0实现的QWidget版富文本编辑器
- Qt5版NeHe OpenGL教程6-10
- QT5下实现基于TCP发送和接接收文件
- PyQt5_gpl-5.11.3.zip
- qtribbon可用
- qt5串口简单实现图片、pdf文件的传输
- qt5.8实现rtsp流播放
- QT5检测USB设备
- Qt5.5 开发 Creo3.0 案例
-
Qt5.8 QMediaPla
yer 音乐播放器 - qt5之学生管理系统
- qt5-qtwebkit-5.6.2-1.el7.x86_64.rpm
- Qt5 for windows plugin dll
- qt5_V4L2_Camera 实现摄像头实时画面显示
- qml模仿实现的qt creator
- Qt5实战项目之
评论
共有 条评论