码迷,mamicode.com
首页 > Web开发 > 详细

JsonCpp 判断 value 中是否有某个KEY

时间:2017-12-10 18:20:29      阅读:374      评论:0      收藏:0      [点我收藏+]

标签:ring   bool   ifstream   eric   json   reader   ret   cpp   name   

JsonCpp如何判断是否有某个KEY,使用json[“key”]和isXXX的函数即可。
如果json中没有key键,则会创建一个空成员或者返回一个空成员。

bool isNull() const;
bool isBool() const;
bool isInt() const;
bool isUInt() const;
bool isIntegral() const;
bool isDouble() const;
bool isNumeric() const;
bool isString() const;
bool isArray() const;
bool isObject() const;

例子:

ifstream ifs;
ifs.open("testR.json");

Json::Reader reader;
Json::Value value;
if (!reader.parse(ifs,value,false))
{
	return -1;
}

if (value["name"].isString())
{
	string name = value["name"].asString();
	cout << "name:" << name << endl;
}

如果value中没有 name 键就不会提取该数据。

  

JsonCpp 判断 value 中是否有某个KEY

标签:ring   bool   ifstream   eric   json   reader   ret   cpp   name   

原文地址:http://www.cnblogs.com/SZxiaochun/p/8017527.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!