• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Cpper
            C/C++高級工程師 Android高級軟件工程師 IT集成工程師 音頻工程師 熟悉c,c++,java,c#,py,js,asp等多種語言 程序猿
            #include <QStringList>
            #include 
            <QJsonArray>
            #include 
            <QJSonDocument>
            #include 
            <QJsonObject>
            #include 
            <QJsonValue>
            #include 
            <QFile>
            #include 
            <QDebug>
            #include 
            "test.h"

            #define STR(o) #o
            #define INSERT_ITEM(object,o) object.insert(STR(o),o);
            #define INSERT_LIST(object,o)\
                {\
                    auto array 
            = QJsonArray::fromStringList(o);\
                    
            object.insert(STR(o),array);\
                }

            struct Unit
            {
                QString result;
                QString author;
                QString description;
                QString notes;

                QStringList key;
                
            int minValue;
                QStringList items;
                QStringList attachment;

                QString toString()
                {
                    QJsonObject 
            object;
                    INSERT_ITEM(
            object,result)
                    INSERT_ITEM(
            object,author)
                    INSERT_ITEM(
            object,description)
                    INSERT_ITEM(
            object,notes)
                    INSERT_LIST(
            object,key)
                    INSERT_ITEM(
            object,minValue)
                    INSERT_LIST(
            object,items)
                    INSERT_LIST(
            object,attachment)

                    QJsonDocument doc;
                    doc.setObject(
            object);
                    
            return doc.toJson(QJsonDocument::JsonFormat::Compact);
                }

                
            bool loadFromFile(const QString& filename)
                {
                    QFile file(filename);
                    
            if(!file.open(QIODevice::ReadOnly))
                        
            return false;

                    QByteArray buffer 
            = file.readAll();
                    file.close();

                    QJsonParseError error;
                    QJsonDocument doc(QJsonDocument::fromJson(buffer,
            &error));

                    
            if(error.error != QJsonParseError::NoError)
                    {
                        qDebug() 
            << "parse json file:"<<filename<< " failed!";
                        
            return false;
                    }

                    auto 
            object = doc.object();
                    
            if(!object.contains("result"|| !object.contains("key"))
                    {
                        qDebug() 
            << "invalid json file:" << filename << " structure!";
                        
            return false;
                    }

                    result 
            = object[STR(result)].toString();
                    author 
            = object[STR(author)].toString();
                    description 
            = object[STR(description)].toString();
                    notes 
            = object[STR(notes)].toString();

                    minValue 
            = object[STR(minValue)].toInt();

                    auto fn 
            = [](const QJsonArray& array)->QStringList
                    {
                        QStringList items;
                        
            foreach(auto item,array)
                            items 
            += item.toString();
                        
            return items;
                    };

                    key 
            = fn(object[STR(key)].toArray());
                    items 
            = fn(object[STR(items)].toArray());
                    attachment 
            = fn(object[STR(attachment)].toArray());
                    
            return true;
                }
            };
             
            void test()
            {
                Unit unit;
                unit.attachment.append(
            "acchemtn1");
                unit.attachment.append(
            "acchemtn2");

                unit.key.append(
            "key1");
                unit.author 
            = "author";
                unit.description 
            = "this is a remark";
                unit.items.append(
            "item1");
                unit.items.append(
            "item2");
                unit.items.append(
            "item3");
                unit.minValue 
            = 1;
                unit.notes 
            = "notes";

                QFile file(
            "file.json");
                file.open(QIODevice::WriteOnly);

                file.write(unit.toString().toLocal8Bit().data());

                file.close();

                qDebug() 
            << unit.toString();
            }
            posted on 2019-08-13 14:43 ccsdu2009 閱讀(897) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            国产精品久久久久久久久久影院| 女同久久| 精品久久久久久亚洲| www性久久久com| 久久久国产精品| 青草国产精品久久久久久| 国产高清国内精品福利99久久| 久久亚洲中文字幕精品一区四| 亚洲色大成网站www久久九| 久久福利青草精品资源站免费| 久久影院亚洲一区| 国内精品久久久久久99| 亚洲国产精品嫩草影院久久 | 久久精品无码一区二区WWW| 亚洲AV无码1区2区久久| 久久影视国产亚洲| 久久久综合九色合综国产| 亚洲AV日韩精品久久久久久| 久久国产成人精品国产成人亚洲| 日本欧美久久久久免费播放网| 国产福利电影一区二区三区久久老子无码午夜伦不 | 国产精品激情综合久久| 亚洲日本va中文字幕久久| 久久亚洲av无码精品浪潮| 99热精品久久只有精品| 国产精品99久久免费观看| 亚洲人成伊人成综合网久久久| 久久这里有精品| 少妇被又大又粗又爽毛片久久黑人| 免费观看久久精彩视频| 美女写真久久影院| 国产精品欧美久久久久天天影视 | 国产午夜精品久久久久免费视| 久久精品国产亚洲AV香蕉| 国产精品亚洲综合久久| yy6080久久| 欧美黑人激情性久久| 人人狠狠综合久久88成人| 久久发布国产伦子伦精品 | 久久精品中文字幕有码| 久久综合色区|