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