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. mac上安装ruby

    (转:http://www.cnblogs.com/daguo/p/4097263.html) 以下代码区域,带有 $ 打头的表示需要在控制台(终端)下面执行(不包括 $ 符号) 步骤0 - 安装系统 ...

  2. BZOJ 3527 [Zjoi2014]力 ——FFT

    [题目分析] FFT,构造数列进行卷积,挺裸的一道题目诶. 还是写起来并不顺手,再练. [代码] #include <cmath> #include <cstdio> #inc ...

  3. java之线程池面试题

    面试官:线程池有哪些?分别的作用是什么? 常用的线程池有: newSingleThreadExecutor newFixedThreadExecutor newCacheThreadExecutor ...

  4. 在VMWare下为CentOS设置静态IP通过NAT访问外网

    一.背景 安装好的CentOS系统默认是通过DHCP自动分配地址来共享主机的IP以达到访问外网的目的,但是因为莫名的原因无法访问外网.只好改为通过静态IP的方式访问外网. 二.操作步骤 2.1 确认开 ...

  5. 巴蜀2904 MMT数

    Description FF博士最近在研究MMT数. 如果对于一个数n,存在gcd(n,x)<>1并且n mod x<>0 那么x叫做n的MMT数,显然这样的数可以有无限个. ...

  6. Codevs 2989 寻找somebody

    时间限制: 2 s 空间限制: 8000 KB 题目等级 : 钻石 Diamond 题目描述 Description 在一个n*m的方阵中 寻找somebody的位置 有可能k不存在输出“bianta ...

  7. shell按日期自动切割nginx日志脚本

    shell按日期自动切割nginx日志脚本 参考:自学it网 http://www.zixue.it/. #nginx日志切割脚本 #author:ce #!/bin/bash #设置日志文件存放目录 ...

  8. 漫话最小割 part1

    codeforces 724D [n个城市每个城市有一个特产的产出,一个特产的最大需求.当i<j时,城市i可以运最多C个特产到j.求所有城市可以满足最大的需求和] [如果直接最大流建图显然会T. ...

  9. Paul Graham:梦寐以求的编程语言

    我的朋友曾对一位著名的操作系统专家说他想要设计一种真正优秀的编程语言.那位专家回答,这是浪费时间,优秀的语言不一定会被市场接受,很可能无人使用,因为语言的流行不取决于它本身.至少,那位专家设计的语言就 ...

  10. LibieOJ 6165 一道水题 (线性筛)

    题目链接 LOJ6165 题目意思其实就是求LCM(1, 2, 3, ..., n) 直接用线性筛求出1到1e8之间的所有质数 然后对于每个质数p,他对答案的贡献为$p^{i}$ 其中$p^{i}$小 ...