jsoncpp 简单案例

jsoncpp库文件下载:

下载jsoncpp


案例:

// json_test_2010.cpp : 定义控制台应用程序的入口点。
//

/************************************************************************/
/*
author:郑金玮
time:2014/07/04
desc:impl parse json format files using jsoncpp libs
*/
/************************************************************************/

#include "stdafx.h"
#include <iostream>
#include <cassert>
#include <fstream>
#include <json.h>

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



int _tmain(int argc,_TCHAR* argv[])
{
	std::ifstream ifs;
	ifs.open("..//test.json");
	assert(ifs.is_open());

	Json::Reader reader;
	Json::Value root;

	if (!reader.parse(ifs,root,false))
	{
		return -1;
	}

	std::string name = root["name"].asstring();
	int age = root["age"].asInt();

	std::cout<<"name:"<<name<<std::endl;
	std::cout<<"age:"<<age<<std::endl;


	system("pause");
	return 0;
}


test.json:




相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...