jsonCpp做的很强大,这里,我自己进行了编译,修改成了lib方式
这里我的编程环境 VC 6
#include "stdafx.h"
#pragma warning(disable : 4786)
#include <iostream>
#include <fstream>
#include "json/json.h"
#pragma comment(lib,"jsonlibmtd.lib")
#define SIZE 10;
using namespace std;
// int main(int argc, char* argv[])
// {
//
// Json::Value root;
// Json::FastWriter fast_writer;
//
// Json::Value Person;
//
// Person["name"] = "Tsiannian";
// Person["age"] = "23";
// root.append(Person);
//
// Person["name"] = "zSai";
// Person["age"] = "21";
// root.append(Person);
//
// std::cout << fast_writer.write(root) << endl;
// getchar();
// return 0;
// }
int main(int argc, char* argv[])
{
fstream file("test.json");
if (!file)
{
cout<<"Open file test.json fail!!!"<<endl;
getchar();
return -1;
}
Json::Value root;
Json::Reader reader;
Json::FastWriter fast_writer;
if (!reader.parse(file, root, false))
{
return false;
}
int size = root.size();
for (int i = 0; i < size; ++i)
{
int nCode = root[i]["errcode"].asInt();
string data = root[i]["bookname"].asString();
string downcount = root[i]["data"].asString();
cout<<"name:"<<nCode<<"\t data:"<<data<<"\t downcount:"<<downcount<<endl;
}
getchar();
return 0;
}
上面的代码是使用别人的,自己修改了一下
内容
"test.json"
[{"errcode":0,"bookname":"dasemimi","data":"ffff","downcount":"1","rmb":"1","id":"6"},
{"errcode":0,"bookname":"xaiosemimi","data":"fffffffffffff","downcount":"0","rmb":"0","id":"7"},
{"errcode":0,"bookname":"dasfsfdsadfsd","data":"ssss","downcount":"0","rmb":"0","id":"12"}]
测试代码及lib下载
http://download.csdn.net/detail/u012607841/6903835