// MyJsonTest.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <fstream>
#include <cassert>
#include "json/json.h" using namespace std;
/**************************************************************
技术博客
http://www.cnblogs.com/itdef/ 技术交流群
群号码:324164944 欢迎c c++ windows驱动爱好者 服务器程序员沟通交流
**************************************************************/ void test1() {
Json::Value root;
Json::FastWriter writer;
Json::Value person; person["FileName"] = "test1";
person["fileLength"] = ""; // 4G以内文件
person.removeMember("fileLength");
root.append(person);
person["FileName"] = "test2";
person["fileLength"] = ""; // 4G以内文件
root.append(person);
person["FileName"] = "test3";
person["fileLength"] = ""; // 4G以内文件
root.append(person); std::string json_file = writer.write(root); ofstream ofs;
ofs.open("test1.json", ios::trunc);
assert(ofs.is_open());
ofs << json_file;
ofs.close();
} int test2() {
Json::Reader pJsonParser;;
string strJson = "{\"name\":\"tom\",\"sex\":\"男\",\"age\":\"24\",\"friends\":[{\"name\":\"chen\",\"sex\":\"男\"},{\"name\":\"li\",\"sex\":\"女\"}]}";
Json::Value tempVal; if (!pJsonParser.parse(strJson, tempVal))
{
cout << "parse error" << endl;
return -;
} string name = tempVal["name"].asString();
string sex = tempVal["sex"].asString();
string age = tempVal["age"].asString(); Json::Value friends = tempVal["friends"];
for (int i = ; i < friends.size(); i++) {
cout << friends[i]["name"].asString() << endl;
}
cout << "name = " << name << " age = " << age << " sex = " << sex << endl; return ;
} void test3() {
Json::Value root;
Json::Value arrayObj;
Json::Value item;
Json::FastWriter writer;
for (int i = ; i<; i++)
{
item["key"] = i;
arrayObj.append(item); //数组项添加
}
root["key1"] = "value1";
root["key2"] = "value2";
root["key3"] = 0x100;
root["key4"] = true;
root["key5"] = "中国人";
item = root["key5"];
root["array"] = arrayObj;
std::cout << root.toStyledString();
std::cout << writer.write(root);
} void test4() {
char* config_doc = "{\"encoding\" : \"UTF-8\",\"plug-ins\" : [\"python\",\"c++\",\"ruby\"],\"indent\" : { \"length\" : 3, \"use_space\" : true }}"; Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse(config_doc, root);
if (!parsingSuccessful)
{
// report to the user the failure and their locations in the document.
std::cout << "Failed to parse configuration\n";
return;
} // Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
// such member.
std::string encoding = root.get("encoding", "UTF-8").asString();
// Get the value of the member of root named 'encoding', return a 'null' value if
// there is no such member.
const Json::Value plugins = root["plug-ins"];
for (int index = ; index < plugins.size(); ++index) // Iterates over the sequence elements.
std::cout << plugins[index].asString() << std::endl; std::cout << root["indent"].get("length", ).asInt() << std::endl; std::cout << root["indent"].get("use_space", true).asBool() << std::endl;; // ...
// At application shutdown to make the new configuration document:
// Since Json::Value has implicit constructor for all value types, it is not
// necessary to explicitly construct the Json::Value object:
//root["encoding"] = getCurrentEncoding();
//root["indent"]["length"] = getCurrentIndentLength();
//root["indent"]["use_space"] = getCurrentIndentUseSpace(); Json::StyledWriter writer;
// Make a new JSON document for the configuration. Preserve original comments.
std::string outputConfig = writer.write(root); // You can also use streams. This will put the contents of any JSON
// stream at a particular sub-value, if you'd like.
//std::cin >> root["subtree"]; // And you can write to a stream, using the StyledWriter automatically.
std::cout << root;
} void test5() {
Json::Reader reader;
Json::Value root;
Json::StyledStreamWriter writer;
std::string text = "{ \"first\": \"James\", \"last\": \"Bond\", \"nums\": [0, 0, 7] }";
std::ofstream outFile; // Parse JSON and print errors if needed
if (!reader.parse(text, root)) {
std::cout << reader.getFormatedErrorMessages();
exit();
}
else { // Read and modify the json data
std::cout << "Size: " << root.size() << std::endl;
std::cout << "Contains nums? " << root.isMember("nums") << std::endl;
root["first"] = "Jimmy";
root["middle"] = "Danger"; // Write the output to a file
outFile.open("output.json");
writer.write(outFile, root);
outFile.close();
}
} int main()
{
test5(); return ;
}

考虑在打包时候使用json记录打包文件信息
但是json似乎不支持64位数据 那么大于4G的文件长度怎么记录?这是个问题

代码见

http://www.oschina.net/code/snippet_614253_56645

jsoncpp学习的更多相关文章

  1. C++之jsoncpp学习

    最新由于客户端要用到jsoncpp,所以自己也跟着项目的需求学了一下jsoncpp.以前没用过xml,但是感觉接触json后,还蛮好用的. 参考地址 http://jsoncpp.sourceforg ...

  2. JSONCPP学习笔记

    基本使用 使用jsoncpp库解析.修改.打印JSON串 源文件 $ cat main.cpp #include <iostream> #include "json/json.h ...

  3. Qt学习日记篇-Qt中使用Curl和jsonCpp

    1.Qt中安装并使用jsonCPP库 1.1  官网下载.https://sourceforge.net/projects/jsoncpp/    解压文件得到 jsoncpp-src-0.5.0 文 ...

  4. 从直播编程到直播教育:LiveEdu.tv开启多元化的在线学习直播时代

    2015年9月,一个叫Livecoding.tv的网站在互联网上引起了编程界的注意.缘于Pingwest品玩的一位编辑在上网时无意中发现了这个网站,并写了一篇文章<一个比直播睡觉更奇怪的网站:直 ...

  5. Angular2学习笔记(1)

    Angular2学习笔记(1) 1. 写在前面 之前基于Electron写过一个Markdown编辑器.就其功能而言,主要功能已经实现,一些小的不影响使用的功能由于时间关系还没有完成:但就代码而言,之 ...

  6. ABP入门系列(1)——学习Abp框架之实操演练

    作为.Net工地搬砖长工一名,一直致力于挖坑(Bug)填坑(Debug),但技术却不见长进.也曾热情于新技术的学习,憧憬过成为技术大拿.从前端到后端,从bootstrap到javascript,从py ...

  7. 消息队列——RabbitMQ学习笔记

    消息队列--RabbitMQ学习笔记 1. 写在前面 昨天简单学习了一个消息队列项目--RabbitMQ,今天趁热打铁,将学到的东西记录下来. 学习的资料主要是官网给出的6个基本的消息发送/接收模型, ...

  8. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  9. Unity3d学习 制作地形

    这周学习了如何在unity中制作地形,就是在一个Terrain的对象上盖几座小山,在山底种几棵树,那就讲一下如何完成上述内容. 1.在新键得项目的游戏的Hierarchy目录中新键一个Terrain对 ...

随机推荐

  1. Oracle-SQL高级查询

    --一个题目涉及到的50个Sql语句 --(下面表的结构以给出,自己在数据库中建立表.并且添加相应的数据,数据要全面些. 其中Student表中,SId为学生的ID) ---------------- ...

  2. TypeScript学习笔记(八) - 声明文件

    本篇将介绍TypeScript的声明文件,并简单演示一下如何编写和使用声明文件.本篇也是这个系列的最后一篇. 一.声明文件简介 TypeScript作为JavaScript的超集,在开发过程中不可避免 ...

  3. LG4719 【模板】动态dp 及 LG4751 动态dp【加强版】

    题意 题目描述 给定一棵\(n\)个点的树,点带点权. 有\(m\)次操作,每次操作给定\(x,y\),表示修改点\(x\)的权值为\(y\). 你需要在每次操作之后求出这棵树的最大权独立集的权值大小 ...

  4. Java移位运算符 “

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/zjx409/article/details/37569055 左移运算符(<<) 基本使 ...

  5. FastAdmin 插件配置文件 info.ini 中的 state 什么意思?

    FastAdmin 插件配置文件 info.ini 中的 state 什么意思? 在插件配置中有一个 state ,这是配置插件开关的.

  6. 【转】Linux shell的&&和||

    原文网址:http://www.2cto.com/os/201302/189655.html Linux shell的&&和||   shell 在执行某个命令的时候,会返回一个返回值 ...

  7. ivy antlib shemalocation

    <?xml version="1.0" encoding="UTF-8"?> <project name="yourproject& ...

  8. 【python】Python框架、库和软件资源大全

    很多来自世界各地的程序员不求回报的写代码为别人造轮子.贡献代码.开发框架.开放源代码使得分散在世界各地的程序员们都能够贡献他们的代码与创新. Python就是这样一门受到全世界各地开源社区支持的语言. ...

  9. Educational Codeforces Round 37-F.SUM and REPLACE题解

    一.题目 二.题目链接 http://codeforces.com/contest/920/problem/F 三.题意 给定$N$个范围在$[1, 1e6)$的数字和$M$个操作.操作有两种类型: ...

  10. 【Codeforces】Codeforces Round #492 (Div. 2) (Contest 996)

    题目 传送门:QWQ A:A - Hit the Lottery 分析: 大水题 模拟 代码: #include <bits/stdc++.h> using namespace std; ...