当前位置:网站首页>QT parse string into JSON data and parse
QT parse string into JSON data and parse
2022-07-28 06:32:00 【Schoolmate Xiaotu!】
Preface
Call an interface in the company , I use the method encapsulated by my colleagues , The return value of the string, So I thought QString Can it be converted to JSON data , And analyze it .qt Pass through QJsonDocument take QString To JSON, as long as QString Can be converted to json, Many parsing json The problem of data is naturally easy to solve .
Case study :
{
"StatusCode": 200,
"ErrCode": 0,
"Msg": "success",
"Data": [
{
"SchoolID": "S-05061411",
"schoolName": " Southeast University ",
"SchoolType": 5
}
]
}
The code is as follows :( It is concluded that SchoolID and schoolName)
QJsonParseError jsonError;
QJsonDocument jsonDoc(QJsonDocument::fromJson(schoolInfo.toStdString().data(), &jsonError)); //schoolInfo For the above string of data QString Variable of type
if(jsonError.error == QJsonParseError::NoError){
QJsonObject rootObj = jsonDoc.object();
//------ The reader modifies... According to the actual situation
QJsonArray data = rootObj.value("Data").toArray(); // obtain Data,Data In this case, it's an array , therefore toArray()
for(int i=0;i<data.size();i++){
// Parsing arrays
QJsonObject schoolInfo=data.at(i).toObject(); // Each item in the array is another json
QString schoolId = schoolInfo.value("SchoolID").toString(); // Parse string
QString schoolName_1 = schoolInfo.value("schoolName").toString(); // Analysis of Chinese
int schoolType = schoolInfo.value("SchoolType").toInt(); // Parsing numbers
}
//------ The reader modifies... According to the actual situation
}else {
qDebug() << "json error!" << jsonError.errorString(); //json There's a problem with the data
}
Be careful : There is no problem with the code , If an error is reported, it may be because the header file is not inserted
It's not easy to code words , If this blog is helpful to you , Please praise the collection , Thank you very much ! There is something wrong , Can comment on the area of communication .
边栏推荐
- 基于 YOLOV5 的 SAR 图像舰船检测
- ClickHouse 中的公共表表达式CTE
- qt批量操作控件,并设置信号槽
- Electric fast burst (EFT) design - EMC series hardware design notes 4
- Varistor design parameters and classic circuit recording hardware learning notes 5
- qt绘画事件-设置背景图片
- Perl入门学习(十)格式化输出
- Learning notes on hardware circuit design 2 -- step-down power circuit
- ICC2(一)Preparing the Design
- Detailed explanation of creepage distance and electrical clearance
猜你喜欢

PyTorch 学习笔记 4 —— 自动计算梯度下降 AUTOGRAD

Detailed explanation of word mail merge function: after merging, multiple word documents are generated and blank pages are deleted
![[yolov5] environment construction: win11 + mx450](/img/04/4da9b3748d5f45ef73cffcc48f8609.png)
[yolov5] environment construction: win11 + mx450

毕业论文 | 文献综述应该怎么写

IMS-FACNN(Improved Multi-Scale Convolution Neural Network integrated with a Feature Attention Mecha

Mae mask self encoding is scalable learning

mixup_ratio

clock tree分析实例

qt绘画事件-设置背景图片

Efficient Net_ V2
随机推荐
Chinese display problem of calendarextender control
clickhouse聚合之内存不足怎么办?那就提升聚合性能
NPM yarn related operations
Pytorch learning notes 2 - about tensor
PT 基于Multi Voltage的Physical Aware
Hugging face 的入门使用
CLIP Learning Transferable Visual Models From Natural Language Supervision
EMC experiment practical case ESD electrostatic experiment
How to pop up the message dialog box
qt解析字符串转为json数据并解析
Pycharm2019设置编辑器主题和默认代码
TVs tube parameters and selection
OpenGL的开发环境配置【VS2017】+常见问题
Esxi on arm 10/22 update
Redhawk Dynamic Analysis
PyTorch 学习笔记 1 —— Quick Start
Convert data in grilview into datatable
Bag of tricks training convolution network skills
低功耗设计-Power Switch
ICC2(四)Routing and Postroute Optimization