void rapidjson1(){ rapidjson::StringBuffer s;
rapidjson::Writer<rapidjson::StringBuffer> writer(s); writer.StartObject(); // Between StartObject()/EndObject(),
writer.Key("hello"); // output a key,
writer.String("world"); // follow by a value.
writer.Key("t");
writer.Bool(true);
writer.Key("f");
writer.Bool(false);
writer.Key("n");
writer.Null();
writer.Key("i");
writer.Uint(123);
writer.Key("pi");
writer.Double(3.1416);
writer.Key("a");
writer.StartArray(); // Between StartArray()/EndArray(),
for (unsigned i = 0; i < 4; i++)
writer.Uint(i); // all values are elements of the array.
writer.EndArray();
writer.EndObject();
// {"hello":"world","t":true,"f":false,"n":null,"i":123,"pi":3.1416,"a":[0,1,2,3]}
std::cout << s.GetString() << std::endl;
}

document.json

{
"name": "xiaoming",
"gender": "boy",
"hobby": [
"足球",
"篮球",
"电影"
],
"score": {
"数学": 91.5,
"语文": 95.5,
"英语": 96
},
"lover": {
"name": "xiaohong",
"gender": "girl",
"hobby": [
"画画",
"跳舞",
"唱歌"
],
"score": {
"数学": 78.5,
"语文": 89,
"英语": 90
}
}
}
void rapidjson2(){

    std::ifstream t("/home/leoxae/document1.json");
// std::ifstream t("/home/leoxae/CLionProjects/KeekoAIRobot/data/ninstructionRecognition/bcb2_feature.json");
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>()); rapidjson::Document document;
document.Parse(str.c_str()); rapidjson::Value::ConstMemberIterator iter = document.FindMember("name");
if(iter != document.MemberEnd()){
cout << "name : " << iter->value.GetString() << endl;
} iter = document.FindMember("gender");
if(iter != document.MemberEnd()){
cout << "gender : " << iter->value.GetString() << endl;
} if(document.HasMember("hobby")){
cout << "hobby : " << endl;
const rapidjson::Value& childValue = document["hobby"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetString() << endl;
}
} if(document.HasMember("score")){
cout << "score : " << endl;
const rapidjson::Value& childIter = document["score"];
for(rapidjson::Value::ConstMemberIterator it = childIter.MemberBegin(); it != childIter.MemberEnd(); ++it){
cout << " " << it->name.GetString() << " : " << it->value.GetDouble() << endl;
}
} if(document.HasMember("lover")){
cout << "lover : " << endl;
const rapidjson::Value& chileValue = document["lover"];
rapidjson::Value::ConstMemberIterator chileIter = chileValue.FindMember("name");
if(chileIter != chileValue.MemberEnd()){
cout << " " << "name : " << chileIter->value.GetString() << endl;
} chileIter = chileValue.FindMember("gender");
if(chileIter != chileValue.MemberEnd()){
cout << " " << "gender : " << chileIter->value.GetString() << endl;
} if(chileValue.HasMember("hobby")){
cout << " " << "hobby : " << endl;
const rapidjson::Value& chile2Value = chileValue["hobby"];
for(rapidjson::SizeType i = 0; i < chile2Value.Size(); ++i){
cout << " " << chile2Value[i].GetString() << endl;
}
} if(chileValue.HasMember("score")){
cout << " " << "score : " << endl;
const rapidjson::Value& child2Iter = chileValue["score"];
for(rapidjson::Value::ConstMemberIterator it = child2Iter.MemberBegin(); it != child2Iter.MemberEnd(); ++it){
cout << " " << it->name.GetString() << " : " << it->value.GetDouble() << endl;
}
}
} }

ninstr.json

{"\u6269\u5c551": [0, 592],
"\u6269\u5c552": [592, 1232],
"\u6269\u5c553": [1232, 2073],
"\u6269\u5c554": [2073, 2874],
"\u6269\u5c555": [2874, 3786],
"\u6269\u5c556": [3786, 4683],
"\u6269\u5c557": [4683, 5267],
"\u6269\u5c558": [5267, 6151],
"\u6269\u5c559": [6151, 6895],
"\u6269\u5c5510": [6895, 7694],
"\u5730\u57ab\u524d\u8fdb": [7694, 8790],
"\u5730\u57ab\u5de6\u8f6c": [8790, 10237],
"\u5730\u57ab\u53f3\u8f6c": [10237, 11617],
"P1": [11617, 12809], "P2": [12809, 13680],
"\u5f00\u59cb": [13680, 15049],
"\u7ed3\u675f": [15049, 16417],
"\u5730\u57ab\u524d\u8fdb\u5c0f": [16417, 17113],
"\u5730\u57ab\u5de6\u8f6c\u5c0f": [17113, 18433],
"\u5730\u57ab\u53f3\u8f6c\u5c0f": [18433, 19954],
"\u5f00\u59cb\u5c0f": [19954, 21242],
"\u7ed3\u675f\u5c0f": [21242, 22571],
"\u6682\u505c": [22571, 23785]}
void rapidjson3(){

//    std::ifstream t("/home/leoxae/document.json");
// std::ifstream t("/home/leoxae/CLionProjects/KeekoAIRobot/data/ninstructionRecognition/bcb2_feature.json");
std::ifstream t("/home/leoxae/ninstr.json");
std::string str((std::istreambuf_iterator<char>(t)),
std::istreambuf_iterator<char>()); rapidjson::Document document;
document.Parse(str.c_str()); //扩展1
if(document.HasMember("扩展1")){
cout << "扩展1 : " << endl;
const rapidjson::Value& childValue = document["扩展1"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
} //扩展2
if(document.HasMember("扩展2")){
cout << "扩展2 : " << endl;
const rapidjson::Value& childValue = document["扩展2"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//扩展3
if(document.HasMember("扩展3")){
cout << "扩展3 : " << endl;
const rapidjson::Value& childValue = document["扩展3"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//扩展4
if(document.HasMember("扩展4")){
cout << "扩展4 : " << endl;
const rapidjson::Value& childValue = document["扩展4"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//扩展5
if(document.HasMember("扩展5")){
cout << "扩展5 : " << endl;
const rapidjson::Value& childValue = document["扩展5"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//扩展6
if(document.HasMember("扩展6")){
cout << "扩展6 : " << endl;
const rapidjson::Value& childValue = document["扩展6"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//扩展7
if(document.HasMember("扩展7")){
cout << "扩展7 : " << endl;
const rapidjson::Value& childValue = document["扩展7"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//扩展8
if(document.HasMember("扩展8")){
cout << "扩展8 : " << endl;
const rapidjson::Value& childValue = document["扩展8"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//扩展9
if(document.HasMember("扩展9")){
cout << "扩展9 : " << endl;
const rapidjson::Value& childValue = document["扩展9"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//扩展10
if(document.HasMember("扩展10")){
cout << "扩展10 : " << endl;
const rapidjson::Value& childValue = document["扩展10"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//地垫前进
if(document.HasMember("地垫前进")){
cout << "地垫前进 : " << endl;
const rapidjson::Value& childValue = document["地垫前进"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//地垫左转
if(document.HasMember("地垫左转")){
cout << "地垫左转 : " << endl;
const rapidjson::Value& childValue = document["地垫左转"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//地垫右转
if(document.HasMember("地垫右转")){
cout << "地垫右转 : " << endl;
const rapidjson::Value& childValue = document["地垫右转"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//P1
if(document.HasMember("P1")){
cout << "P1 : " << endl;
const rapidjson::Value& childValue = document["P1"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//P2
if(document.HasMember("P2")){
cout << "P2 : " << endl;
const rapidjson::Value& childValue = document["P2"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//开始
if(document.HasMember("开始")){
cout << "开始 : " << endl;
const rapidjson::Value& childValue = document["开始"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//结束
if(document.HasMember("结束")){
cout << "结束 : " << endl;
const rapidjson::Value& childValue = document["结束"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//地垫前进小
if(document.HasMember("地垫前进小")){
cout << "地垫前进小 : " << endl;
const rapidjson::Value& childValue = document["地垫前进小"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//地垫左转小
if(document.HasMember("地垫左转小")){
cout << "地垫左转小 : " << endl;
const rapidjson::Value& childValue = document["地垫左转小"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//地垫右转小
if(document.HasMember("地垫右转小")){
cout << "地垫右转小 : " << endl;
const rapidjson::Value& childValue = document["地垫右转小"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//开始小
if(document.HasMember("开始小")){
cout << "开始小 : " << endl;
const rapidjson::Value& childValue = document["开始小"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//结束小
if(document.HasMember("结束小")){
cout << "结束小 : " << endl;
const rapidjson::Value& childValue = document["结束小"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
//暂停
if(document.HasMember("暂停")){
cout << "暂停 : " << endl;
const rapidjson::Value& childValue = document["暂停"];
for(rapidjson::SizeType i = 0; i < childValue.Size(); ++i){
cout << " " << childValue[i].GetInt() << endl;
}
}
}
void readrapidjson(){
string strJsonTest = "{\"item_1\":\"value_1\",\"item_2\":\"value_2\",\"item_3\":\"value_3\",\"item_4\":\"value_4\",\"item_arr\":[\"arr_vaule_1\",\"arr_vaule_2\"]}";
rapidjson::Document docTest;
docTest.Parse<0>(strJsonTest.c_str()); if (!docTest.HasParseError())
{
for (rapidjson::Value::ConstMemberIterator itr = docTest.MemberBegin(); itr != docTest.MemberEnd(); itr++)
{
rapidjson::Value jKey;
rapidjson::Value jValue;
rapidjson::Document::AllocatorType allocator;
jKey.CopyFrom(itr->name, allocator);
jValue.CopyFrom(itr->value,allocator);
if (jKey.IsString())
{
string name = jKey.GetString();
// printf("\r\nname: %s\r\n",name.c_str());
cout << "name=>>:" << name << endl;
}
}
} }

rapidjson解析与构造实例的更多相关文章

  1. Cocos2d-X网络编程(5) 使用Rapidjson解析数据

    Json基础及28种c++解析库性能对比 JSON 概念和特点:     JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation)     JSON ...

  2. 在SQL中使用CLR提供基本函数对二进制数据进行解析与构造

      二进制数据包的解析一般是借助C#等语言,在通讯程序中解析后形成字段,再统一单笔或者批量(表类型参数)提交至数据库,在通讯程序中,存在BINARY到struct再到table的转换. 现借助CLR提 ...

  3. SAX方式解析XML文件实例

    books.XML文件: 书籍book.java实体类: public class Book { private String id; private String name; private Str ...

  4. 两种库解析、构造 JSON

    1.用CJSON库 1.1解析Json 需要解析的JSON文件: { "name":"Tsybius", , "sex_is_male":t ...

  5. dom4j解析xml字符串实例

    DOM4J 与利用DOM.SAX.JAXP机制来解析xml相比,DOM4J 表现更优秀,具有性能优异.功能强大和极端易用使用的特点,只要懂得DOM基本概念,就可以通过dom4j的api文档来解析xml ...

  6. 小白详细解析C#反射特性实例

    套用MSDN上对于反射的定义:反射提供了封装程序集.模块和类型的对象(Type 类型).可以使用反射动态创建类型的实例,将类型绑定到现有对象,或从现有对象获取类型并调用其方法或访问其字段和属性.如果代 ...

  7. 【零基础】AI神经元解析(含实例代码)

    一.序言 关于“深度学习”大部分文章讲的都云里雾里,直到看到“床长”的系列教程以及<深度学习入门:基于Python的理论与实现>,这里主要是对这两个教程进行个人化的总结,目标是让“0基础” ...

  8. Request 接收参数乱码原理解析三:实例分析

    通过前面两篇<Request 接收参数乱码原理解析一:服务器端解码原理>和<Request 接收参数乱码原理解析二:浏览器端编码原理>,了解了服务器和浏览器编码解码的原理,接下 ...

  9. 【转】adns解析库——域名解析实例(C++、linux)

    转自:http://blog.csdn.net/fty8788/article/details/7480334 adns是一个开源的dns解析库 官方文档:http://www.chiark.gree ...

随机推荐

  1. Hibernate 错误的问题

    配了好几次的Hibernate,老是在create BeanFactory的时候fail.我是用MyEclipse自带的HIbernate,直接加进去的. private static final T ...

  2. Output of C++ Program | Set 13

    Predict the output of following C++ program. 1 #include<iostream> 2 using namespace std; 3 4 c ...

  3. oracle(数据文件)

    --创建数据文件 create tablespace--创建表空间同时创建数据文件 create temporary tablespace --创建临时表空间的同时创建临时数据文件 alter tab ...

  4. BeanDefinitionLoader spring Bean的加载器

    spring 容器注册bean , 会把bean包装成beanDefinition 放进spring容器中,beanDefinitionLoader就是加载bean的类 . 一.源码 class Be ...

  5. SpringSecurity Oauth2.0

    1.用户认证分析 上面流程图描述了用户要操作的各个微服务,用户查看个人信息需要访问客户微服务,下单需要访问订单微服务,秒杀抢购商品需要访问秒杀微服务.每个服务都需要认证用户的身份,身份认证成功后,需要 ...

  6. ActiveMQ(一)——简介

    一.ActiveMQ简介 ActiveMQ是什么ActiveMQ是Apache推出的,一款开源的,完全支持JMS1.1和J2EE1.4规范的JMS Provider实现的消中间件(MOM) Activ ...

  7. 深度学习初探——符号式编程、框架、TensorFlow

    一.命令式编程(imperative)和符号式编程(symblic) 命令式: import numpy as np a = np.ones(10) b = np.ones(10) * 2 c = b ...

  8. [BUUCTF]PWN——ciscn_2019_ne_5

    ciscn_2019_ne_5 题目附件 步骤: 例行检查,32位,开启了nx保护 试运行一下程序,看一下程序的大概执行情况 32位ida载入,shift+f12查看程序里的字符串,发现了flag字符 ...

  9. Kubernetes-API Server

    前言 本篇是Kubernetes第十四篇,大家一定要把环境搭建起来,看是解决不了问题的,必须实战. Kubernetes系列文章: Kubernetes介绍 Kubernetes环境搭建 Kubern ...

  10. CF166A Rank List 题解

    Content 有 \(n\) 个元素,第 \(i\) 个元素包含两个值 \(a_i,b_i\),按照以下规则排序: 如果对于 \(i\neq j\) 有 \(a_i\neq a_j\),则按照 \( ...