• <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 閱讀(886) 評論(0)  編輯 收藏 引用 所屬分類: QT編程
             
            亚洲乱码中文字幕久久孕妇黑人| 激情伊人五月天久久综合| 亚洲精品成人久久久| 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久精品中文字幕久久| 亚洲精品乱码久久久久久蜜桃图片 | 久久精品国产亚洲AV不卡| 国产精品久久久香蕉| 久久受www免费人成_看片中文| 色综合久久夜色精品国产| 国产精品久久久久久久久| 久久夜色精品国产噜噜亚洲AV| 伊人色综合久久天天人手人婷| 国产精品永久久久久久久久久| 久久精品国产亚洲77777| 久久国产精品成人片免费| 久久精品国产亚洲AV嫖农村妇女| 2020国产成人久久精品| 国产精品一区二区久久精品涩爱| 亚洲?V乱码久久精品蜜桃 | 国产精品视频久久久| AV无码久久久久不卡蜜桃| 久久人妻少妇嫩草AV蜜桃| 久久亚洲国产成人精品性色| 久久99精品久久久久久齐齐| 狠狠色丁香婷婷久久综合不卡| 99久久国产综合精品麻豆| 久久99亚洲综合精品首页| 要久久爱在线免费观看| 91精品免费久久久久久久久| 精品久久久久久久久中文字幕| 狠狠色噜噜色狠狠狠综合久久| 一本久久a久久精品vr综合| 久久免费精品一区二区| 久久人人爽人人爽人人片AV不| 99久久成人国产精品免费| 一级a性色生活片久久无| 91精品久久久久久无码| 久久精品国产亚洲av影院| 亚洲国产成人久久综合碰| 精品综合久久久久久97超人|