JsonCpp使用

前端之家收集整理的这篇文章主要介绍了JsonCpp使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
资源下载:
http://oss.Metaparadigm.com/json-c/


tar -zxvf json-c-0.9.tar.gz
./configure --prefix=/usr/local/json-c-0.9(没有prefix选项,默认的是/usr/local/lib/)
make && make install




windows编译冲突问题
json_object.h 32 行
//typedef int boolean; modify by shenyu
typedef unsigned char boolean;




error while loading shared libraries: libjson.so.0:
root
vi /etc/ld.so.conf 最后添加一行
/usr/local/lib/libjson.so.0






jsoncpp
资源下载:
http://sourceforge.net/projects/jsoncpp/files/latest/download?source=files

tar -zxvf jsoncpp-src-0.5.0.tar.gz


linux 下安装需要先装 scons




http://www.scons.org
http://sourceforge.net/projects/scons/files/scons/2.1.0/scons-2.1.0.tar.gz/download
解压后:
cd /home/qingtian/scons-2.1.0

python setup.py install
python setup.py install --standard-lib 安装到python标准目录

cd /home/qingtian/jsoncpp-src-0.5.0
python /home/qingtian/scons-2.1.0/script/scons platform=linux-gcc






python /usr/local/app/qingtian/scons-2.1.0/script/scons platform=linux-gcc

生成文件目录:
/home/qingtian/jsoncpp-src-0.5.0/include
/home/qingtian/jsoncpp-src-0.5.0/libs/linux-gcc-4.1.2

cp /home/qingtian/jsoncpp-src-0.5.0 /usr/local/jsoncpp -r
cp /home/leoxshen/jsoncpp-src-0.5.0 /usr/local/jsoncpp -r


cp /usr/local/app/leoxshen/jsoncpp-src-0.5.0 /usr/local/jsoncpp -r
编译代码时引用即可


#错误处理
mqq@38_183:~/qingtian/jsoncpp-src-0.5.0> python /usr/local/app/qingtian/scons-2.1.0/script/scons platform=linux-gcc
Traceback (most recent call last):
File "/usr/local/app/qingtian/scons-2.1.0/script/scons",line 187,in <module>
import SCons.Script
ImportError: No module named SCons.Script

如果安装不上,需要root权限,执行命令

python setup.py install --standard-lib 安装到python标准目录


------------------------------------------------------------------------------------ test 程序--------------------------------------------------------------------

#include <iostream> #include <string> #include "json/json.h" using namespace std; void json_writer() { Json::Value rootA; Json::Value root; Json::FastWriter fast_writer; root["REGION_ID"] = "600901"; root["DATA_TOTAL_NUM"] = 456278; rootA["KEY"] = "1"; rootA["NUM"] = "9"; rootA["entry"] = root; std::cout << fast_writer.write(root) << std::endl; std::cout << fast_writer.write(rootA) << std::endl; Json::Value jsonArry; jsonArry.append(root); jsonArry.append(root); jsonArry.append(rootA); std::cout << fast_writer.write(jsonArry) << std::endl; } void json_reader() { string strJson = "{\"key1\":\"value1\",\"array\":[{\"key2\":\"value2\",\"key3\":\"aa\"},{\"key2\":\"value3\",\"key3\":\"bb\"},{\"key2\":\"value4\",\"key3\":\"cc\"}]}"; Json::Reader reader; Json::Value val; if(!reader.parse(strJson,val)) return ; std::string str = val["key1"].asString(); cout<<"str = "<< str<<endl; std::string str2 = val["key11"].asString(); cout<<"str2 = "<< str2<<endl; int a = val["key13"].asInt(); cout<<"a = "<< a<<endl; Json::Value obj_array = val["array"]; for (int i = 0; i< obj_array.size(); i++) { std::cout << obj_array[i]["key2"].asString()<<"|"<< obj_array[i]["key3"].asString() << std::endl; } } 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; */ json_writer(); json_reader(); //char * p = ( char *) malloc(10); return 0; }

原文链接:https://www.f2er.com/json/290197.html

猜你在找的Json相关文章