要操作json文件收先要对json语法有所了解,了解了语法就好写好解析了。不过还要注意语法。刚开始的时候在网上找了不少这方面的资料看。
其中,这篇对我帮助极大,https://www.techieliang.com/2017/12/718/,现贴出来。
QStringList Dialog::pointsfromjson()//**************从json中读取数据
{
QFile file("D:\\QT\\QTtest\\13.json");
QStringList valueList;
if(file.open(QIODevice::ReadOnly))
{
qDebug()<<"文件已打开";
QByteArray allData=file.readAll();
file.close();
QJsonParseError jsonparsererror;
QJsonDocument jsondocument=QJsonDocument::fromJson(allData,&jsonparsererror);
if(!jsondocument.isNull()&&jsonparsererror.error==jsonparsererror.NoError)
{
qDebug()<<"文件解析成功";
if(jsondocument.isObject())
{
QJsonObject jsonobj=jsondocument.o