阅读 112

jsonCPP

jsoncpp是一个用于操作json数据的C++开源库
代码地址:
使用文档:

使用过程中遇到一个错误,这里作为记录

错误

error C4996: ‘Json::Reader‘: Use CharReader and CharReaderBuilder instead
error C4996: ‘Json::Reader::Reader‘: Use CharReader and CharReaderBuilder instead

解决方法

Json::CharReaderBuilder readerBuild;
Json::CharReader* reader(readerBuild.newCharReader());

示例


#include 
#include "json/json.h"


int main()
{
	std::cout << "Hello world" << std::endl;

	const char* strValue = "{\"file_path\": \"./test_models/test.obj\", \"filename\":\"test.obj\", \"code_id\": 3 }";
	Json::CharReaderBuilder readerBuild;
	Json::CharReader* jsonReader(readerBuild.newCharReader());
	Json::Value jsonValue;
	JSONCPP_STRING jsonErrs;
	bool isParse = jsonReader->parse(strValue, strValue + std::strlen(strValue), &jsonValue, &jsonErrs);
	if (isParse && 0 == jsonErrs.size()){
		std::string filePath = jsonValue["file_path"].asString();
		std::string fileName = jsonValue["filename"].asString();
		int codeId = jsonValue["code_id"].asInt();
		std::cout << "filePath: " << filePath << " fileName: " << fileName << " codeId: " << codeId << std::endl;
	}
	
	return 0;
}

原文:https://www.cnblogs.com/xiaxuexiaoab/p/14574884.html

文章分类
代码人生
文章标签
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐