jsoncpp的读写操作
来源:互联网 发布:淘宝网皇冠店铺转让 编辑:程序博客网 时间:2024/06/06 06:37
代码如下
#include <fstream>#include <cassert>#include <string>#include <iostream>#include "json/json.h"#pragma comment(lib, "lib_json.lib")using namespace std;int main(){{//读操作[{"name" : "xiaoy", "age" :17} , {"name" : "xiaot", "age" : 20}]ifstream ifs;ifs.open("f:\\test.json");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 << " " << age << endl;}}{//写操作[{"age":100,"name":"hello world"}]Json::Value root;Json::FastWriter writer;Json::Value person;person["name"] = "hello, world";person["age"] = 100;root.append(person);string json_file = writer.write(root);ofstream ofs;ofs.open("f:\\test.json");assert(ofs.is_open());ofs << json_file;}{//读操作{"name" : "小楼一夜听春雨","age" : 27}ifstream ifs;ifs.open("f:\\test.json");assert(ifs.is_open());Json::Reader reader;Json::Value root;if (!reader.parse(ifs, root, false)){return -1;}string name = root["name"].asString();int age = root["age"].asInt();cout << name << " " << age << endl;}return 0;}
0 0
- jsoncpp的读写操作
- 使用JsonCpp读写Json数据
- c++ jsoncpp操作
- JsonCpp操作数组对象
- jsoncpp文件操作
- JSONCPP操作帮助
- 读写模版的操作
- xml的读写操作
- 文件的读写操作
- 文件的读写操作
- nandflash的读写操作
- 文件的读写操作
- nandflash 的读写操作
- 配置文件的读写操作
- 文件的读写操作
- 简单的读写操作
- plist的读写操作
- nandflash的读写操作
- 【C语言】编写函数实现库函数atoi,把字符串转换成整形(考虑数字过大)
- oracle 中用pl/sql编辑记录里面的值 for update
- ArrayList和LinkedList的区别
- Alice's Game - HDU 3544 博弈
- linux中mkdir创建目录命令使用说明
- jsoncpp的读写操作
- 【C语言】编写函数实现库函数atof
- Git 命令参考中文整理
- Python浅析之类的写法
- 图解告诉你怎么在VS2010下调试DLL
- jdk install, Ubuntu
- C#+Oracle:ATM自助取款机开发
- BZOJ 1012 最大数maxnumber(单调队列)
- HDU 5277 YJC counts stars (二维平面图求最大团)