easiest way to parse JSON in Qt 4.7

后端 未结 6 2027
甜味超标
甜味超标 2020-12-13 09:44

I need to parse JSON object through Qt. What is the easiest/fastest way to do it?

6条回答
  •  鱼传尺愫
    2020-12-13 10:15

    I would recommend qjson-backport, as it uses the same API as in Qt5.

    You can conditionally load the library when you use Qt4, and use the default implementation when using Qt5.

    My qjson.pri file looks like:

    !greaterThan(QT_MAJOR_VERSION, 4): {
    
        INCLUDEPATH += \
            $$PWD
    
        SOURCES += \
            $$PWD/qjson.cpp \
            $$PWD/qjsonarray.cpp \
            $$PWD/qjsondocument.cpp \
            $$PWD/qjsonobject.cpp \
            $$PWD/qjsonparser.cpp \
            $$PWD/qjsonvalue.cpp \
            $$PWD/qjsonwriter.cpp
    
        HEADERS += \
            $$PWD/qjson_p.h \
            $$PWD/qjsonarray.h \
            $$PWD/qjsondocument.h \
            $$PWD/qjsonobject.h \
            $$PWD/qjsonparser_p.h \
            $$PWD/qjsonvalue.h \
            $$PWD/qjsonwriter_p.h
    
    }
    

提交回复
热议问题