当前位置:网站首页>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 .
边栏推荐
- qt批量操作控件,并设置信号槽
- clickhouse聚合之内存不足怎么办?那就提升聚合性能
- MySQL join skills
- Web scrolling subtitles (marquee example)
- USB network native driver for esxi updated to support esxi7.0.1
- CLIP Learning Transferable Visual Models From Natural Language Supervision
- Measure computer battery capacity
- ICC2分析时序的神器 analyze_design_violations
- NPM yarn related operations
- T-sne dimension reduction visualization
猜你喜欢

机器学习笔记 5 —— Logistic Regression

详解安装msdn 2015及其注意事项

T-sne dimension reduction visualization

set_ case_ analysis

雷达成像 Matlab 仿真 1 —— LFM信号及其频谱

ICC2分析时序的神器 analyze_design_violations

Fluke dtx-sfm2 single mode module of a company in Hangzhou - repair case

Esxi on arm 10/22 update

CLIP Learning Transferable Visual Models From Natural Language Supervision

clickhouse聚合之内存不足怎么办?那就提升聚合性能
随机推荐
Efficient Net_ V2
ClickHouse 中的公共表表达式CTE
Overall understanding of PLC
Surge impact immunity experiment (surge) -emc series Hardware Design Notes 6
USB network native driver for esxi updated to support esxi7.0.1
How can fluke dsx2-5000 and dsx2-8000 modules find the calibration expiration date?
error: redefinition of ‘xxx‘
Chinese display problem of calendarextender control
Convert data in grilview into datatable
clickhouse聚合之内存不足怎么办?那就提升聚合性能
mysql删表不删库
Cautious speculation about fusion on Apple silicon
Example of frameset usage
Beginners choose sensors
Web scrolling subtitles (marquee example)
Analysis of MOSFET damage at the moment of power failure of isolated power supply
An example of bill printing
MATLAB signal processing
OpenGL快速配置方法
Cronbach’s α?KMO系数?因子载荷?史上最易懂的问卷信效度分析教程!!!(SPSS和AMOS)