Windows10 VS2017 C++ Json解析(使用jsoncpp库)

1.项目必须是win32
2.生成的lib_json.lib放到工程目录下
3.incldue的头文件放到工程目录,然后设置工程->属性->配置属性->vc++目录->包含目录
4.工程->属性->配置属性->c/c+±>代码生成->运行库,设置运行库为多线程调试 (/MTd)

首先从github下载最新版jsoncpp,0.10.7
https://github.com/open-source-parsers/jsoncpp/releases
在makefile目录的msvc2010打开工程进行编译,将库文件makefiles\msvc2010\Debug\lib_json.lib添加到工程目录,如上步骤2,然后将include目录拷贝到工程目录,按照上边步骤3设置,然后如上步骤4调整设置
解析字符串json,写码:

#include "pch.h"
#include <iostream>
#include <json.h>

#pragma comment(lib, "lib_json.lib")

using namespace std;

int main()
{
	const char* str = "{\"uploadid\": \"UP000000\",\"code\": 100,\"msg\": \"\",\"files\": \"\"}";

	Json::Reader reader;
	Json::Value root;
	if (reader.parse(str, root))  // reader将Json字符串解析到root,root将包含Json里所有子元素  
	{
		std::string upload_id = root["uploadid"].asString();  // 访问节点,upload_id = "UP000000"  
		int code = root["code"].asInt();    // 访问节点,code = 100 
		cout << "upload_id: " << upload_id << endl;
		cout << "code: " << code << endl;
	}
}

在这里插入图片描述

参考文章:
http://www.cnblogs.com/liaocheng/p/4243731.html
https://blog.csdn.net/shufac/article/details/52710100

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值