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);
  • 相关阅读:
    线段树入门总结
    从零基础学三分查找
    Codeforces Beta Round #1 A,B,C
    isupper()函数
    matlab字符串操作总结
    hdu 4873 ZCC Loves Intersection(大数+概率)
    设计模式入门之桥接模式Bridge
    有关UIWebView的SSL总结
    vmware虚拟机上linux操作系统进行tty1~tty6切换方法和具体步骤
    Python BeautifulSoup4 使用指南
  • 原文地址:https://www.cnblogs.com/zhehan54/p/9366931.html
Copyright © 2011-2022 走看看