Using the C + + JSON library under MAC OS x

Source: Internet
Author: User

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

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.