1. Download Jsoncpp
http://sourceforge.net/projects/jsoncpp/files/
2. Download SCons
Http://sourceforge.net/projects/scons/files/scons/2.1.0/scons-2.1.0.tar.gz/download
3, Decompression scons-2.1.0.tar.gz
TAR-ZVXF scons-2.1.0.tar.gz
My extraction is in the/opt/json/scons-2.1.0 directory.
4, go to the decompression directory scons-2.1.0 below, execute the command:
sudo python setup.py install
5, decompression Jsconcpp
TAR-ZVXF jsoncpp-src-0.5.0.tar.gz
My decompression is under the/opt/json/jsoncpp-src-0.5.0.
6, enter into the Jsoncpp decompression directory, execute the command:
sudo scons PLATFORM=LINUX-GCC
7. Copy the JSON folder under the/jsoncpp-src-0.5.0/include/directory to the/usr/include/
8, the JSONCPP-SRC-0.5.0/LIBS/LINUX-GCC-4.9.1/directory under the libjson_linux-gcc-4.9.1_libmt.a copy to/usr/local/lib/, and for the convenience of use, Rename it to Libjson.a
8. Test code
//json.cpp#include <iostream>#include <json/json.h>using namespace STD;intMain () {stringtest="{\" id\ ": 1,\" name\ ": \" Kurama\ "}"; Json::reader Reader; Json::value Value;if(Reader.parse (Test,value)) {if(!value["id"].isnull ()) {cout<<value["id"].asint () <<endl;cout<<value["Name"].asstring () <<endl; } }return 0;}
Compile: You need to specify the link library (the file that you just renamed):
g++ Json.cpp-ljson
Output:
"Above is a comprehensive online multi-article collation, in this record, to prevent forgetting"
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Using the C + + JSON library under Linux