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的更多相关文章

  1. Tomjson - 一个"短小精悍"的 json 解析库

    Tomjson,一个"短小精悍"的 json 解析库,tomjson使用Java语言编写,主要作用是把Java对象(JavaBean)序列化为json格式字符串,将json格式字符 ...

  2. fastjson是阿里巴巴的开源JSON解析库

    fastjson的API十分简洁. String text = JSON.toJSONString(obj); //序列化 VO vo = JSON.parseObject("{...}&q ...

  3. python 中的json解析库

    当一个json 数据很大的时候.load起来是很耗时的.python中常见的json解析库有cjson,simplesjson,json, 初步比较了一下, 对于loads来讲 simplejson ...

  4. Tomjson - json 解析库

    Tomjson - 一个"短小精悍"的 json 解析库 Tomjson,一个"短小精悍"的 json 解析库,tomjson使用Java语言编写,主要作用是把 ...

  5. C++的Json解析库:jsoncpp和boost

    C++的Json解析库:jsoncpp和boost - hzyong_c的专栏 - 博客频道 - CSDN.NET C++的Json解析库:jsoncpp和boost 分类: 网络编程 开源库 201 ...

  6. Android JSON解析库Gson和Fast-json的使用对比和图书列表小案例

    Android JSON解析库Gson和Fast-json的使用对比和图书列表小案例 继上篇json解析,我用了原生的json解析,但是在有些情况下我们不得不承认,一些优秀的json解析框架确实十分的 ...

  7. C++的Json解析库:jsoncpp和boost(转)

    原文转自 http://blog.csdn.net/hzyong_c/article/details/7163589 JSON(JavaScript Object Notation)跟xml一样也是一 ...

  8. 常用json解析库比较及选择 fastjson & gson

    一.常用json解析库比较及选择 1.简介 fastjson和gson是目前比较常用的json解析库,并且现在我们项目代码中,也在使用这两个解析库. fastjson 是由阿里开发的,号称是处理jso ...

  9. [转]C++的Json解析库:jsoncpp和boost

    JSON(JavaScript Object Notation)跟xml一样也是一种数据交换格式,了解json请参考其官网http://json.org,本文不再对json做介绍,将重点介绍c++的j ...

随机推荐

  1. [luoguP3413] SAC#1 - 萌数(数位DP)

    传送门 gtm的数位dp! 看到好多题解,都是记忆化搜索,好像非常方便啊,但是我还是用递推好了,毕竟还是有些类似数位dp的题用递推的思路,记忆化做不了,现在多培养一下思路 首先这道题, 只看长度大于等 ...

  2. 洛谷P3759 - [TJOI2017]不勤劳的图书管理员

    Portal Description 给出一个\(1..n(n\leq5\times10^4)\)的排列\(\{a_n\}\)和数列\(\{w_n\}(w_i\leq10^5)\),进行\(m(m\l ...

  3. 算法总结——主席树(poj2104)

    题目: Description You are working for Macrohard company in data structures department. After failing y ...

  4. ArrayList构造函数有哪些

    ArrayList 构造函数有(三种): public ArrayList(int initialCapacity) public ArrayList() public ArrayList(Colle ...

  5. PHP中的验证码类(准备篇)

    <!--code.php内容--> <?php //开启session session_start(); include "vcode.class.php"; / ...

  6. PHP实现当前文件夹下所有文件和文件夹的遍历

    <?php function myScandir($dir){ static $flag=''; //设置缩进显示格式 $files = scandir($dir);//读取当前文件夹的文件 $ ...

  7. Codeforces Round #267 (Div. 2) C. George and Job (dp)

    wa哭了,,t哭了,,还是看了题解... 8170436                 2014-10-11 06:41:51     njczy2010     C - George and Jo ...

  8. js Math [ 随机数、绝对值、四舍五入、进一取整、舍去取整、最大值、最小值、圆周率 ]

    <script> /* 数学对象:Math */ with (document) { write('<br>-3.5的绝对值:'+Math.abs(-3.5)); write( ...

  9. HTML 中 SELECT 选项分组

    <select name="viewType"> <option value selected>选择排序/显示方式</option> <o ...

  10. 测试开发系列之Python开发mock接口(三)

    于进入主题了,前面的准备工作都已经做好了,下面就开始写逻辑的代码了,代码我已经写好了,每行都加了注释,不明白的可以留言.   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 ...