jsoncpp 使用
2013-05-11 00:00
330 查看
// json.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <string> #include <iostream> #include <fstream> #include <ctime> // for time #include <cstdlib> // for rand srand using namespace std; #include <windows.h> // for tickcount64 #include "json/json.h" /**@brief low letter*/ static const char* sLetters = "abcdefghijklmnopqrstuvwxyz"; /**@brief low letter length*/ static const int sLen = strlen(sLetters); /** * describe generate random string for test * param{lenth} size of string to generation * return a random string */ string getRandomString(int lenth) { string s(lenth, ' '); srand(time(0)); for(int i=0; i<lenth; ++i) { s += sLetters[rand()%sLen]; } return s; } /** * describe save json to local file * param{fn} file name to save * return void */ static void SaveToFile(const char* fn) { int i = 0; int j = 0; Json::Value root; // json root // dd_type, root member keys, which can be got by Value::members function , // you can use Value::isMember to test whether a key is belong to the Value static const char* dd_type[] = { "online", "local", "favorite", NULL}; srand(time(0)); while (dd_type[j]) { Json::Value items(Json::arrayValue); // json array type int cnt = rand()%20 + 100; for (int k=0; k<cnt; ++k) { Json::Value item; item["id"] = i++; item["url"] = getRandomString(rand()%10 + 5) + ".com"; item["read"] = i%2; items.append(item); } root[dd_type[j++]] = items; } { ofstream out(fn, ofstream::out | ofstream::binary); if (out.is_open()) { out << root; out.close(); } } } int _tmain(int argc, _TCHAR* argv[]) { LONG64 s = GetTickCount64(); SaveToFile("out.json"); cout << "OK, time elapsed: " << GetTickCount64() - s << " ms"; getchar(); return 0; }
相关文章推荐
- VS2008中使用JSONCPP方法小结
- 使用jsoncpp解析JSON数据
- jsoncpp使用
- 【C++】jsoncpp的安装与使用
- 关于jsoncpp的使用,转载自cnblogs,链接如下:
- 【C++】JSON数据解析——jsoncpp的使用(下)
- C++ 解析Json VC6 中编译、使用jsoncpp
- cocos2dx中Http链接以及使用JsonCPP解析的简单函数
- C++使用JsonCpp库操作json格式数据示例
- C++使用 jsoncpp 解析json数据
- C++ JSONCPP使用
- c++使用jsoncpp(vs2015)
- VS2010中使用JSONCPP方法
- C++简单使用Jsoncpp来读取写入json文件
- JSONcpp使用.
- c++ 第三方json解析库 jsoncpp的使用
- JSON数据解析——jsoncpp的使用(上)
- 在使用jsonCPP过程中,使用Debug正常,但是使用Relese出现找不到json_value.asm
- linux下jsoncpp编译与使用
- 6、JsonCpp简单使用(2)