jsoncpp简介

来源:互联网 发布:热设计软件 编辑:程序博客网 时间:2024/05/01 06:16

Jsoncpp官网:http://jsoncpp.sourceforge.net/old.html


Jsoncpp相当于是c++的一个字典库。


Jsoncpp库中常用的类有;

Json::Value

Json::Reader

Json::Write


1.把字符串转化Json格式的字典:

Json::Value root

Json::Reader read

char* str="{\"key1\":\"value1\",\"key2\":\"value2\"}";

read.parse(str,root);

cout<<root["key1"]<<endl;


显示value1


2.遍历Json

Json::Value::Members mem=retry_info.getMemberNames();
for(Json::Value::Members::iterator iter=mem.begin();iter!=mem.end();++iter){
cout<<"key"<<*iter<<endl;
cout<<"value"<<root[*iter]<<endl;
}

                                             
0 0
原创粉丝点击