json ubuntu下安裝
1.首先安裝scons
scons是linux下的自動構建工具,類似cmake。
下載地址
wget http://prdownloads.sourceforge.net/scons/scons-2.2.0.tar.gz
解壓並安裝之,如下
tar zxvf scons-2.2.0.tar.gz
cd scons-2.2.0
sudo python setup.py install
然後配置環境變數,sudo vi /etc/profile
#json environment set
export MYSCONS=/home/gary/localization_ws/json/scons-2.2.0
export SCONS_LIB_DIR=$MYSCONS/engine
export PATH=$MYSCONS:$SCONS_LIB_DIR:$PATH
退出後,執行source /etc/profile
jsoncpp的安裝
先下載之http://sourceforge.net/projects/jsoncpp/files/
tar -zxf jsoncpp-src-0.5.0.tar.gz
cd jsoncpp-src-0.5.0
scons platform=linux-gcc
然後,將編譯好的靜態庫和動態庫檔案拷貝考/usr/local/lib下
sudo cp libs/linux-gcc-5.4.0/libjson_linux-gcc-5.4.0_libmt.so /usr/local/lib/
sudo cp libs/linux-gcc-5.4.0/libjson_linux-gcc-5.4.0_libmt.a /usr/local/lib/
將標頭檔案拷貝到/usr/local/include下面
sudo cp -r include/json/ /usr/local/include/
下面進行測試
#include <iostream> #include <json/json.h> using namespace std; int main() { Json::Value root; Json::FastWriter fast; root["DateTime"] = ("23"); root["Name"] = ("hello"); root["class"] = ("12"); cout << fast.write(root) << endl; return 0; }
編譯之g++ test.cpp -o test /usr/local/lib/libjson_linux-gcc-5.4.0_libmt.a
執行./test
{"DateTime":"23","Name":"hello","class":"12"}
done!
ubuntu C++soncpp工具庫解析 json環境搭建(轉) soncpp工具庫解析JSON範例(分PC端和ARM裝置執行兩種)
https://www.douban.com/note/619750040/
一些簡單的例子
https://blog.csdn.net/ccfxue/article/details/51224274