1. Download the C + + JSON library
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. Unzip the scons-2.1.0.tar.gz
TAR-ZVXF scons-2.1.0.tar.gz
4. Go to the Unzip directory scons-2.1.0 below and execute the command:
sudo python setup.py install
5. Unzip the Jsconcpp
TAR-ZVXF jsoncpp-src-0.5.0.tar.gz
6. Go to the Jsoncpp decompression directory and execute the command:
sudo scons PLATFORM=LINUX-GCC
7. You can copy the JSON folder in the/jsoncpp-src-0.5.0/include/directory to/usr/include/, and the JSONCPP-SRC-0.5.0/LIBS/LINUX-GCC-4.9.1/ The libjson_linux-gcc-4.9.1_libmt.a in the directory is copied to/usr/local/lib/and renamed to Libjson.a for ease of use. or add it manually at g++ compile time.
8. Test the code:
1#include <iostream>2#include"Json/json.h"3 using namespacestd;4 5 intMain ()6 {7 Json::value Write_value;8write_value["ID"] =123;9write_value["name"] ="James";Ten stringStr_json =write_value.tostyledstring (); One A Json::reader Reader; - Json::value Read_value; - the if(Reader.parse (Str_json, read_value)) - { - if(!read_value["ID"].isnull ()) - { +cout << read_value["ID"].asint () <<Endl; -cout << read_value["name"].asstring () <<Endl; + } A } at return 0; -}
The compile command is g++ cpp_json.cpp-o cpp_json-l./-ljson
(Note: On my PC, the link library libjson.a in the same directory as the source file)
Using the C + + JSON library under MAC OS x