• <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編程
             
            亚洲精品无码久久千人斩| 人妻无码αv中文字幕久久| 久久国产成人午夜AV影院| 久久午夜福利电影| 国产成人精品三上悠亚久久| 欧美一区二区精品久久| 国产一区二区久久久| 国产午夜免费高清久久影院| 久久久久亚洲精品无码网址| 无码人妻久久久一区二区三区 | 亚洲精品tv久久久久| 天天爽天天狠久久久综合麻豆| 亚洲国产精品热久久| 中文字幕无码免费久久| 久久激情亚洲精品无码?V| 久久久久高潮毛片免费全部播放| 国产精品永久久久久久久久久| 久久精品国产亚洲av日韩| 日韩久久无码免费毛片软件| 97久久精品国产精品青草| 亚洲日韩中文无码久久| 亚洲欧美日韩精品久久亚洲区 | 久久久久久毛片免费播放| 久久久噜噜噜久久中文字幕色伊伊| 中文字幕亚洲综合久久| 久久婷婷成人综合色综合| 亚洲精品无码久久久久sm| 亚洲伊人久久成综合人影院 | 久久久久99精品成人片| 久久青青草原精品影院| 97精品国产91久久久久久| 99999久久久久久亚洲| 欧美喷潮久久久XXXXx| 久久99久久99精品免视看动漫 | 国产韩国精品一区二区三区久久| 综合久久一区二区三区 | 91精品国产综合久久久久久| 精品久久8x国产免费观看| 国内精品人妻无码久久久影院 | 69久久精品无码一区二区| 狠狠色丁香久久综合五月|