error C4996: ‘Json::Reader::Char’: Use CharReader and CharReaderBuilder instead
Posted ~小小鸟~
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了error C4996: ‘Json::Reader::Char’: Use CharReader and CharReaderBuilder instead相关的知识,希望对你有一定的参考价值。
1、编译下面代码时,遇到标题中的错误
const char* str = "{\"name\":\"xiaoming\",\"age\":18}"; Json::Value root; Json::Reader reader; if (!reader.parse(str, root)) { cout << "Parse from str failed\n"; return; } string name = root["name"].asCString(); int age = root["age"].asInt(); std::cout << "name: " << name << " age:" << age;
2、解决方法,根据提示修改代码,如下:
Json::CharReaderBuilder b; Json::CharReader* reader(b.newCharReader()); Json::Value root; JSONCPP_STRING errs; bool ok = reader->parse(str, str + std::strlen(str), &root, &errs); if (ok&&errs.size() == 0) { std::string upload_id = root["uploadid"].asString(); // 访问节点,upload_id = "UP000000" int code = root["code"].asInt(); // 访问节点,code = 100 } delete reader;
以上是关于error C4996: ‘Json::Reader::Char’: Use CharReader and CharReaderBuilder instead的主要内容,如果未能解决你的问题,请参考以下文章
error C4996: 'fopen': This function or variable may be unsafe.
error C4996 ‘pugixml_documentload‘ 被声明为已否决的解决方法
vs2013 error c4996: 'fopen': This function or variable may be unsafe
《C语言杂记》解决 error c4996 ‘fopen‘ This function or variable may be unsafe
《C语言杂记》解决 error c4996 ‘fopen‘ This function or variable may be unsafe
VS 编译C错误error C4996: 'scanf': This function or variable may be unsafe. 的解决方案