Jsoncpp使用

常用组件

Value: 支持的类型,null,int,uint,double,string(utf-8),bool,array,object

Writer:

简介: json::value转化为字符串.

使用: Writer 类是一个纯虚类,并不能直接使用。在此我们使用Json::Writer的子类:Json::FastWriterJson::StyledWriterJson::StyledStreamWriter.

-差别:fast是连续的,style是格式好看的,不必要.

eg:

Json::FastWriter fast_writer;

std::cout << fast_writer.write(root) << std::endl;

Reader:

简介: 将字符串转为Json::value.

eg:

Json::Reader reader;
Json::Value json_object;
const char* json_document = "{/"age/" : 26,/"name/" : /"huchao/"}";
if (!reader.parse(json_document, json_object))
    return 0;

std::cout << json_object["name"] << std::endl;
std::cout << json_object["age"] << std::endl;

常用成员:

as系列函数: asString,asInt,将Json::value转化为相应类型. 
is系列函数: 判断

参考:http://blog.csdn.net/wangchangshuai0010/article/details/18180223

posted on 2017-12-11 13:06  willaty  阅读(480)  评论(0编辑  收藏  举报

导航