您的位置:首页 > Web前端 > JavaScript

VC静态链接库的使用方法 以及jsoncpp使用方法

2016-01-25 17:20 543 查看
#include "stdafx.h"
#include <stdio.h>
#include "json.h"
#include <fstream>
#include <cassert>

using namespace std;

//静态库的使用方法,还需要将生成的静态库拷贝到当前工作目录下。主意静态库的编译方式要与当前项目的保持一致
#pragma comment(lib, "json_vc71_libmtd.lib")

int _tmain(int argc, _TCHAR* argv[])
{
#if 0
//-------创建JSON文件的方法-------
Json::Value root;
Json::FastWriter write;
Json::Value person;

person["name"] = "cain";
person["age"] = 24;
root.append(person);

std::string json_file = write.write(root);
cout << json_file << endl;
getchar();
#else
//-------解析JSON文件的方法-------
//--附上测试用文件json.txt:
//[{"name" : "xiaoy", "age" :17} , {"name" : "xiaot", "age" : 20}]

ifstream ifs;
ifs.open("json.txt");
assert(ifs.is_open());

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

string name;
int age;
int size = root.size();

for (int i = 0; i < size; ++i)
{
name = root[i]["name"].asString();
age = root[i]["age"].asInt();

cout << name << endl;
cout << age << endl;
}
getchar();
#endif
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mfc vc json