C++ JSON解析库RapidJSON
https://github.com/Tencent/rapidjson
jsontext.txt
{
"result" :
[
{
"face_id" : "a9cebf8d5ae6fff514d8d2d8e07fa55b",
"img_id" : "12.jpg",
"people_name" : "白活",
"similarity" : 100
},
{
"face_id" : "7f2de0e85bede3171c839d0dcabd849f",
"img_id" : "6.jpg",
"people_name" : "布伊什",
"similarity" : 55.379097
},
{
"face_id" : "40ebb31e8af7237a73dec9f242885a7e",
"img_id" : "2.jpg",
"people_name" : "布衣食",
"similarity" : 52.59766
}
]
}
rapidjson_test.cpp
#include <iostream>
#include <fstream>
#include <iomanip>
#include "rapidjson/document.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
int main()
{
using namespace std;
using namespace rapidjson;
cout << "parsing test" << endl;
string line, jsonText;
ifstream ifs("json_text.txt");
while (getline(ifs, line))
jsonText.append(line);
Document document;
document.Parse(jsonText.c_str());
const auto &array = document["result"].GetArray();
for (const auto &e : array)
{
const auto &faceId = e["face_id"].GetString();
const auto &imgId = e["img_id"].GetString();
const auto &peopleName = e["people_name"].GetString();
const auto &similarity = e["similarity"].GetDouble();
cout << setprecision() << "face_id:\t" << faceId << endl;
cout << "img_id:\t\t" << imgId << endl;
cout << "people_name:\t" << peopleName << endl;
cout << "similarity:\t" << similarity << endl << endl;
}
cout << endl << "generating test" << endl;
Document d;
d.SetObject();
Document::AllocatorType &allocator = d.GetAllocator();
Value arr(kArrayType);
Value elem1(kObjectType);
elem1.AddMember("name", "沃夫", allocator);
elem1.AddMember("gender", "Male", allocator);
elem1.AddMember("age", , allocator);
arr.PushBack(elem1, allocator);
Value elem2(kObjectType);
elem2.AddMember("name", "布伊什", allocator);
elem2.AddMember("gender", "Female", allocator);
elem2.AddMember("age", , allocator);
arr.PushBack(elem2, allocator);
Value elem3(kObjectType);
elem3.AddMember("name", "布衣食", allocator);
elem3.AddMember("gender", "Male", allocator);
elem3.AddMember("age", , allocator);
arr.PushBack(elem3, allocator);
d.AddMember("result", arr, allocator);
StringBuffer strBuf;
Writer<StringBuffer> writer(strBuf);
d.Accept(writer);
cout << strBuf.GetString() << endl;
return ;
}
C++ JSON解析库RapidJSON的更多相关文章
- Tomjson - 一个"短小精悍"的 json 解析库
Tomjson,一个"短小精悍"的 json 解析库,tomjson使用Java语言编写,主要作用是把Java对象(JavaBean)序列化为json格式字符串,将json格式字符 ...
- fastjson是阿里巴巴的开源JSON解析库
fastjson的API十分简洁. String text = JSON.toJSONString(obj); //序列化 VO vo = JSON.parseObject("{...}&q ...
- python 中的json解析库
当一个json 数据很大的时候.load起来是很耗时的.python中常见的json解析库有cjson,simplesjson,json, 初步比较了一下, 对于loads来讲 simplejson ...
- Tomjson - json 解析库
Tomjson - 一个"短小精悍"的 json 解析库 Tomjson,一个"短小精悍"的 json 解析库,tomjson使用Java语言编写,主要作用是把 ...
- C++的Json解析库:jsoncpp和boost
C++的Json解析库:jsoncpp和boost - hzyong_c的专栏 - 博客频道 - CSDN.NET C++的Json解析库:jsoncpp和boost 分类: 网络编程 开源库 201 ...
- Android JSON解析库Gson和Fast-json的使用对比和图书列表小案例
Android JSON解析库Gson和Fast-json的使用对比和图书列表小案例 继上篇json解析,我用了原生的json解析,但是在有些情况下我们不得不承认,一些优秀的json解析框架确实十分的 ...
- C++的Json解析库:jsoncpp和boost(转)
原文转自 http://blog.csdn.net/hzyong_c/article/details/7163589 JSON(JavaScript Object Notation)跟xml一样也是一 ...
- 常用json解析库比较及选择 fastjson & gson
一.常用json解析库比较及选择 1.简介 fastjson和gson是目前比较常用的json解析库,并且现在我们项目代码中,也在使用这两个解析库. fastjson 是由阿里开发的,号称是处理jso ...
- [转]C++的Json解析库:jsoncpp和boost
JSON(JavaScript Object Notation)跟xml一样也是一种数据交换格式,了解json请参考其官网http://json.org,本文不再对json做介绍,将重点介绍c++的j ...
随机推荐
- 构建maven的web项目时注意的问题(出现Error configuring application listener of class org.springframework.web.context.ContextLoaderListener 或者前端控制器无法加载)
构建项目后或者导入项目后,我们需要bulid path--->config build path 特别是maven的依赖一定要 发布到WEB_INF的lib下面,不然在发布项目的时候,这些依赖都 ...
- IntelliJ IDEA 代码提示快捷键
1.写代码时用Alt-Insert(Code|Generate…)可以创建类里面任何字段的getter与setter方法. mac版 是ctrl+enter 2.CodeCompletion(代码完成 ...
- Python之窗口操作之find_window,set_foreground等
在自动化测试过程中,常常需要模拟按键的操作,比如像窗口发送一个按键,实现鼠标点击的功能,在上一篇文章中,我和大家讨论了python文件生成为不依赖与python库的exe文件的方式(需要了解的朋友戳这 ...
- POJ 1125 Stockbroker Grapevine【floyd】
很裸的floyd #include<cstdio> #include<string.h> #include<algorithm> #define maxn 201 ...
- java面试题之什么是ThreadLocal?底层如何实现的?
ThreadLocal是一个解决线程并发问题的一个类,用于创建线程的本地变量,我们知道一个对象的所有线程会共享它的全局变量,所以这些变量不是线程安全的,我们可以使用同步技术.但是当我们不想使用同步的时 ...
- idea打包SpringBoot项目打包成jar包和war
- 打包成jar包 1. <groupId>com.squpt.springboot</groupId> <artifactId>springbootdemo< ...
- eclipse 搭建ruby环境
第一步:获取RDT,http://sourceforge.net/projects/rubyeclipse/files/ 解压该文件,获得features和plugins两个文件夹,将这两个文件夹分别 ...
- c/s委托练习
今天玩了玩C/S开发,也随便练习了很久不用的委托 父窗体中写的代码 #region 委托与事件传递 public delegate void TextChangedHandler(string ...
- linux内核中预留4M以上大内存的方法
在内核中, kmalloc能够分配的最大连续内存为2的(MAX_ORDER-1)次方个page(参见alloc_pages函数, "if (unlikely(order >= ...
- laravel 查询构造器
//查询构造器public function query(){ $bool = DB::table('student')->insert([ ['name' => '王五', 'age' ...