Qt工作笔记-Qt5 利用QJson从文件读取Json并解析
生活随笔
收集整理的這篇文章主要介紹了
Qt工作笔记-Qt5 利用QJson从文件读取Json并解析
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文地址:
https://blog.csdn.net/hp_cpp/article/details/80338116
?
Json文件是這樣:
{"first fruit":{"describe":"an apple","icon":"appleIcon","name":"apple"},"second fruit":{"describe":"an orange","icon":"orangeIcon","name":"orange"},"three fruit array":["eat 0","eat 1","eat 2","eat 3","eat 4"] }存放在本地磁盤。?
利用QJson可以方便的進行解析。
需要包含的頭文件:
#include <QJsonDocument> #include <QJsonParseError> #include <QFile> #include <QJsonObject> #include <QDebug> #include <QJsonArray>運行結果:
key 0 ?is: "first fruit" key 1 ?is: "second fruit" key 2 ?is: "three fruit array" describe is: "an apple" icon is: "appleIcon" name is: "apple" describe is: "an orange" icon is: "orangeIcon" name is: "orange" 0 ?value is: "eat 0" 1 ?value is: "eat 1" 2 ?value is: "eat 2" 3 ?value is: "eat 3" 4 ?value is: "eat 4"
?
總結
以上是生活随笔為你收集整理的Qt工作笔记-Qt5 利用QJson从文件读取Json并解析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Qt工作笔记-MineData相关基本操
- 下一篇: C++与QML信号交互(非Q_PROPE