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

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值