zoukankan      html  css  js  c++  java
  • JSON传输数组的基本操作

    目标JSON结果如下:

    生成JSON的的过程如下:

    Document document;
        Document::AllocatorType& allocator = document.GetAllocator();
    
        //
        Value root(kObjectType);
    
        Value records(kArrayType);
        for (int i = 0;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>(2);
            param[0]=CV_IMWRITE_JPEG_QUALITY;
            param[1]=95;//default(95) 0-100
    
            imencode(".jpg",faceMat,buff,param);
            char* imgData = new char[buff.size()];
            memset(imgData, 0, buff.size());
            for (int ii=0;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);
  • 相关阅读:
    LaTeX不能识别eps文件?
    ubuntu 11.04系统清理(不断更新。。。)
    换Ubuntu邮件客户端Evolution为Thunderbird
    Byobu:打造多任务的Terminal
    Learning the Vi Editor, 6th Edition学习笔记(1)
    Ubuntu:让桌面显示回收站
    3rd Party Repository for Dropbox
    ubuntu 显示隐藏文件
    Ubuntu下的一款Dock工具AWN
    i686和x86_64的区别
  • 原文地址:https://www.cnblogs.com/zhehan54/p/9366931.html
Copyright © 2011-2022 走看看