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; }
相关文章推荐
- XML 与 JSON 优劣对比
- VBA将excel数据表生成JSON文件
- newtonsoft.json解析天气数据出错解决方法
- 修复mysql数据库
- vbs 解析json jsonp的方法
- Extjs4如何处理后台json数据中日期和时间
- C#实现将类的内容写成JSON格式字符串的方法
- JQuery ajax返回JSON时的处理方式 (三种方式)
- jquery JSON的解析方式示例介绍
- nodejs中的fiber(纤程)库详解
- c#版json数据解析示例分享
- ASP JSON类文件的使用方法
- VC中CDC、HDC、pDC区别与联系及相互转换
- Visual C++中MFC消息的分类
- VC实现获取当前正在运行的进程
- vc中SendMessage自定义消息函数用法实例
- VC实现让关闭按钮成灰色不可用的方法
- VC++中的字体设置方法详解
- VC程序设计中CreateProcess用法注意事项
- VC实现批量删除指定文件的方法