QJson
http://qjson.sourceforge.net/
JSONパーサのQJsonをWindowsで使うまでの過程をメモ。
1から実装すると大変だからこういうのはあるものを使わないとね!!
QJsonのソースコードを拾う
tar.gzで落ちてるので拾って解凍
http://sourceforge.net/projects/qjson/files/
ついでに公式にコンパイルの仕方が全部書かれているので見る。
http://qjson.sourceforge.net/get_it/windows.html
MinGW + cmakeの場合を説明。
コンパイルとか
cmakeを行う前にqmakeがある位置までのpathを通す。
X:\...\Qt\バージョン\qt\bin\qmake.exe にある場合は以下になる。
set PATH=X:\...\Qt\バージョン\qt\bin\;%PATH%
cmakeを行う。".."もしっかり含める。
cmake -G "MinGW Makefiles" ..
makeとmake installを行う。
mingw32-make && mingw32-make install
make installが実行されるとこんな感じのログがでる。
[100%] Built target qjson
Install the project...
- Install configuration: "RelWithDebInfo"
- Installing: C:/Program Files/qjson/include/qjson/parser.h
- Installing: C:/Program Files/qjson/include/qjson/parserrunnable.h
- Installing: C:/Program Files/qjson/include/qjson/qobjecthelper.h
- Installing: C:/Program Files/qjson/include/qjson/serializer.h
- Installing: C:/Program Files/qjson/include/qjson/serializerrunnable.h
- Installing: C:/Program Files/qjson/include/qjson/qjson_export.h
- Installing: C:/Program Files/qjson/lib/libqjson.dll.a
- Installing: C:/Program Files/qjson/bin/libqjson.dll
- Installing: C:/Program Files/qjson/share/apps/cmake/modules/FindQJSON.cmake
インストールとか
多分、cmakeでインストール先を指定できると思うけど、わからなかった。
C:/Program Files/qjson/ に必要なモノをまとめて入れてくれたので、これをQtの場所へ移す。
X:\...\Qt\バージョン\qt\にフォルダごと移動する。
使う
プロジェクトファイル(.pro)を開き、ライブラリをリンクするようにする。
win32: LIBS += libqjson.dll
QJsonを使ったちょっとしたサンプルを作った。
http://rying.net/arc/QJsonSample.zip
JSONの規格に合っていたらOK、合ってなかったらNGを出す。
テキストデータをtoAsciiしているのがちょっと不安。
各データの取得は行っていない。
QtCore4.dll, QtGui4.dll, libqjson.dllに依存しているので、実行時はこれらを参照できるようにする。
入力データ例
{ "AAA":"bbb", "ccc":[ "DDD", -1, 3.1415, { "eee": 1.0e-2 } ] }