目标JSON结果如下:

生成JSON的的过程如下:

Document document;
Document::AllocatorType& allocator = document.GetAllocator(); //根
Value root(kObjectType); Value records(kArrayType);
for (int i = ;i< signlogList.size();i++)
{
Value record_info(kObjectType);
record_info.SetObject(); record_info.AddMember("id", signlogList[i].face_id, allocator); Value snapshot_time(kStringType);
snapshot_time.SetString(signlogList[i].snapshot_time.c_str(), allocator); record_info.AddMember("recoTime", snapshot_time, allocator); Mat faceMat = imread(signlogList[i].snapshot_url); vector<uchar> buff;//buffer for coding
vector<int> param = vector<int>();
param[]=CV_IMWRITE_JPEG_QUALITY;
param[]=;//default(95) 0-100 imencode(".jpg",faceMat,buff,param);
char* imgData = new char[buff.size()];
memset(imgData, , buff.size());
for (int ii=;ii < buff.size();ii++)
{
imgData[ii] = buff[ii];
} std::string imgBase64="";
CBase64::Encode((uchar*)imgData, buff.size(),imgBase64); delete[] imgData;
imgData = NULL; Value pic(kStringType); pic.SetString(imgBase64.c_str(), allocator); record_info.AddMember("pic", pic, allocator); record_info.AddMember("sim", signlogList[i].score, allocator); records.PushBack(record_info, allocator);
} root.AddMember("records", records, allocator); string strTime = get_current_datetime(); Value sendTime(kStringType);
sendTime.SetString(strTime.c_str(), allocator); root.AddMember("sendTime", sendTime, allocator); string strMD5 = Common::Utility::generate_md5(strTime+config_info_.tianyu_order.key); Value sign(kStringType);
sign.SetString(strMD5.c_str(), allocator); root.AddMember("sign", sign, allocator);

JSON传输数组的基本操作的更多相关文章

  1. 使用json传输数组实例

    client.php <?php //遍历数组元素,并将元素转码 function array_iconv($data, $in_charset='GBK', $out_charset='UTF ...

  2. AJSX 传输数组

    如果要利用ajax传输数组,或者传输多个(不知道有多少个)class的某一属性的值,例如: 要将这三个数据传入php编辑界面,图片显示有三个数据,但实际上,数据的多少是由数据库所导出的数据 决定的.如 ...

  3. java http post/get 服务端和客户端实现json传输

    注:本文来源于<java http post/get 服务端和客户端实现json传输> 最近需要写http post接口所以学习下. 总的还是不难直接上源码! PostHttpClient ...

  4. json传输二进制的方案【转】

    本文转自:http://wiyi.org/binary-to-string.html json 是一种很简洁的协议,但可惜的是,它只能传递基本的数型(int,long,string等),但不能传递by ...

  5. json在php中的使用之如何转换json为数组

    <?php $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}' ...

  6. MVC中用ajax提交json对象数组

    应用场景:在前端用ajax向服务器提交json对象数组,在controller的以对象数组作为函数的参数,提交的json数组直接转为服务器端的对象数组. 如: 要将json对象数组[{Id:1,Nam ...

  7. No1_4.数组的基本操作_Java学习笔记

    import java.util.Arrays; public class HelloArrayOp { public static void main(String[] args) { // TOD ...

  8. list对象数组,xpath复杂定位校验,POST入参为number数组,POST入参为JSON对象数组

    list对象数组: POST入参为number数组: {    "typeIds":[1,2,3]} POST入参为JSON对象数组,举例: [{    "itemId& ...

  9. javascript:Json 和数组的遍历

    首先看代码示例var json={a:1,b:2,c:3}; //json var array={1,2,3}; //数组 alert(json.a); //弹出1 或alert(json['a']) ...

随机推荐

  1. 解决ci框架php发送邮件附件中文乱码问题

    CI框架发送邮件附件中文出现乱码,是因为php basename()函数不支持中文引起,修改类库 Email.php 文件中 _append_attachments()方法,大致在 1474行 添加如 ...

  2. c++得到窗口句柄

    #include <Windows.h> #include <stdio.h> #include <tchar.h> #include <string.h&g ...

  3. 用 React 整合 LogEntries JavaScript 库

    [编者按]本文作者为 David Posin,主要介绍 React 与 LogEntries 间的相互操作.本文系国内 ITOM 管理平台 OneAPM 编译呈现. 众所周知,React.js已经被证 ...

  4. SecureCRT使用问题记录

    1.破解版下载&安装 参考:https://bbs.feng.com/read-htm-tid-6939481.html 2.session导入 查看 SecureCRT-Preference ...

  5. 使用 PowerShell 管理 Azure 磁盘

    Azure 虚拟机使用磁盘来存储 VM 操作系统.应用程序和数据. 创建 VM 时,请务必选择适用于所需工作负荷的磁盘大小和配置. 本教程介绍如何部署和管理 VM 磁盘. 学习内容: OS 磁盘和临时 ...

  6. Windows10 家庭版没有本地组策略解决方法

    windows 家庭版默认是没有本地组策略的, win+R运行gpedit.msc提示不存在 下面的代码保存一个cmdorbat 脚本文件add_gpedit.cmd, 并执行 add_gpedit. ...

  7. ZooKeeper 集群的安装部署

    0. 说明 ZooKeeper 安装在 s102.s103.s104上,这三个节点同时是 Hadoop 的 DataNode 1. ZooKeeper 本地模式安装配置 1.0 在 s101 上进行安 ...

  8. extern “C”的作用详解

    extern "C"的主要作用就是为了能够正确实现C++代码调用其他C语言代码.加上extern "C"后,会指示编译器这部分代码按C语言的进行编译,而不是C+ ...

  9. python 使用csv 文件写入 出现多余空行数据解决方案

    因为csv.writerow() 方法会造成读取时每条数据后多一条空数据 解决方案如下: 分为两种情况 python2 和 python3 先说python2版本 with open('xxx.csv ...

  10. CSS居中布局

    一:水平居中方案: 1.行内元素 设置 text-align:center 2.定宽块状元素 设置 左右 margin 值为 auto 3.不定宽块状元素 a:在元素外加入 table 标签(完整的, ...