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 ...
随机推荐
- UTF-8转字典
NSString *textStr = ] forKey:[string substringToIndex:range.location]]; }]; NSLog(@"% ...
- bzoj4002 [JLOI2015]有意义的字符串 快速幂
Description B 君有两个好朋友,他们叫宁宁和冉冉. 有一天,冉冉遇到了一个有趣的题目:输入 b;d;n,求((b+sqrt(D)/2)^N的整数部分,请输出结果 Mod 752844341 ...
- spring 如何动态加载properties文件的内容
1. 在xml中配置你的properties路径: <bean id="messageSource" class="org.springframework.cont ...
- 金鹰dreamweaver视频教程下载地址
原文发布时间为:2008-07-30 -- 来源于本人的百度文章 [由搬家工具导入] http://download2.gbaopan.com/c188aecb5e524ab2b2a484c061e0 ...
- csv文件导出
参考博客:http://www.cnblogs.com/mingforyou/p/4103132.html 导入jar包javacsv.jar 链接:http://pan.baidu.com/s/1i ...
- jquery实现表单验证,所以的验证通过后方可提交
<html> <head> <meta http-equiv="content-type" content="tex ...
- Fragment的广播消息接收
这种方式不用在配置文件加东西 广播注册,可以写在Activity(onCreate),也可以写在Fragment(onActivityCreated)里. LocalBroadcastManager ...
- HTML 中 SELECT 选项分组
<select name="viewType"> <option value selected>选择排序/显示方式</option> <o ...
- hdu - 2667 Proving Equivalences(强连通)
http://acm.hdu.edu.cn/showproblem.php?pid=2767 求至少添加多少条边才能变成强连通分量.统计入度为0的点和出度为0的点,取最大值即可. #include & ...
- 【Java TCP/IP Socket】Java NIO Socket VS 标准IO Socket
简介 Java NIO从JDK1.4引入,它提供了与标准IO完全不同的工作方式. NIO包(java.nio.*)引入了四个关键的抽象数据类型,它们共同解决传统的I/O类中的一些问题. 1. ...