首先下载 jsoncpp-src-0.5.0解压,用VS打开里面的工程,进行编译,得到一个 json_vc71_libmtd.lib的文件
用VS创建一个工程,将 json_vc71_libmtd.lib和jsoncpp-src-0.5.0\include\json的文件复制到工程目录下,测试代码如下:
#include "../CommonClass/jsoncpp/json/json.h"
#include <iostream>
#include <string>
using namespace std;
#pragma comment(lib,"json_vc71_libmtd")
void TestJson()
{
ifstream ifst;
ifst.open("config.json");
if (!ifst.is_open())
{
return ;
}
Json::Value root;
Json::Reader reader;
int size = root.size();
if (!reader.parse(ifst,root))
{
return ;
}
cout << root["server_ip"].asCString() << endl;;
Json::Value v;
v["name"]="Jack";
v["isman"]=true;
Json::FastWriter wit;
string str = wit.write(v);
cout << str<< endl;
}
int main()
{
TestJson();
return 0;
}