C ++ uses JsonCPP parse Json string Linux platform

JsonCPP installation

Installation scons

Download :
http://sourceforge.net/projects/scons/files/scons/2.1.0/scons-2.1.0.tar.gz/download
Baidu network disk :
https://pan.baidu.com/s/ 1tW57c9s3iCeoDi4OIDyEPQ password: 2wd5
decompression :

tar -zvxf scons-2.1.0.tar.gz

Unzip into the directory scons-2.1.0, execute the command:

sudo python setup.py install

Installation JsonCPP

Download :
http://sourceforge.net/projects/jsoncpp/
decompression :

tar -zvxf jsoncpp-src-0.5.0.tar.gz

Into jsoncpp unzip directory, execute the command:

sudo scons platform=linux-gcc

Also the following two steps:

  1. The /jsoncpp-src-0.5.0/include/directory jsonfolder to the /usr/local/include/next
  2. The jsoncpp-src-0.5.0/libs/linux-gcc-4.9.1/directory libjson_linux-gcc-4.9.1_libmt.acopied to /usr/local/lib/the next, and for convenience, to renamelibjsoncpp.a

This configuration has been completed, only need to add header files in your code: #include <json/json.h>can be.

Testing procedures

Note: Specify the dynamic link library compiled in the address: -ljsoncpp
test program :

#include <iostream>
#include <string>
#include <json/json.h>

int main(void)
{
     Json::Value root;
     Json::FastWriter fast_writer;

     root["REGION_ID"] = "600901";
     root["DATA_TOTAL_NUM"] = "456278";
     
     std::cout << fast_writer.write(root) << std::endl;
     
     return 0;
}

Compile :
Note: link library -ljsoncppname and you copy to /usr/local/lib/rename under the relevant

g++ -o JsonTest JsonTest.cpp -ljsoncpp

operation result:

$ ./JsonTest 

{"DATA_TOTAL_NUM":"456278","REGION_ID":"600901"}

problem

If you can not find the wrong path, you need to edit the /etc/ld.so.conffile, which records the dynamic library path using the compile-time compiler! Then we put /usr/local/libthe path added to the end of the file on it!

Guess you like

Origin www.cnblogs.com/WindSun/p/12142628.html