Using the C + + JSON library under Linux

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.