头文件

#include "document.h"
#include "prettywriter.h"
#include "filereadstream.h"
#include "filewritestream.h"
#include "stringbuffer.h" using namespace rapidjson;

输出json

std::map<int, POINT> shootMap ;
string strJson;
std::vector<int> everyLoopCount;
string str="abc";
int i=; Document document;
Document::AllocatorType& allocator = document.GetAllocator();
Value root(kObjectType);
Value fixedPoint(kArrayType);//map读取
Value everyLoop(kArrayType);//vector读取 string strX;
string strY;
string strloop;
//map读取,里面存着POINT类型
for (auto iter = shootMap.begin(); iter != shootMap.end(); ++iter)
{
Value arrayBody(kArrayType);
strX = to_string(iter->second.x);
item.SetString(strX.c_str(), strX.size(), allocator);
arrayBody.PushBack(item, allocator);
strY = to_string(iter->second.y);
item.SetString(strY.c_str(), strY.size(), allocator);
arrayBody.PushBack(item, allocator);
fixedPoint.PushBack(arrayBody, allocator);
} //vector 读取,里面存着int类型
for (auto it = everyLoopCount.begin(); it != everyLoopCount.end(); ++it)
{
Value arrayBody(kArrayType);
strloop = to_string(*it);
item.SetString(strloop.c_str(), strloop.size(), allocator);
arrayBody.PushBack(item, allocator);
everyLoop.PushBack(arrayBody, allocator);
}
//map输出
root.AddMember("map", fixedPoint, allocator); //字符串输出
root.AddMember("字符串", StringRef(str.c_str()), allocator); //vector
root.AddMember("vector", everyLoop, allocator); //int
root.AddMember("int", i, allocator); StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
root.Accept(writer);
strJson = buffer.GetString();

读取json

  Document doc;
doc.Parse<>(strJson.c_str());

Value & map= doc["map"];
Value & str= doc["字符串"];

Value & vector= doc["vector"];

Value & int= doc["int"];

//输出到map里

POINT targetPoint;

string temp;

int nKey = 0;

if (map.IsArray())
{
  for (size_t i = 0; i < map.Size(); ++i)
{
  Value & v = map[i];
  if (v.IsArray())
{
    Value& col = v[0];
    temp = col.GetString();
    targetPoint.x = atoi(temp.c_str());

    col = v[1];
    temp = col.GetString();
    targetPoint.y = atoi(temp.c_str());
}
  rMap.insert(map<int, POINT>::value_type(nKey, targetPoint));
  ++nKey;
}
}
temp.empty();

//vector

if (scoreValue.IsArray())
{
  for (size_t i = 0; i < scoreValue.Size(); ++i)
  {
    Value & v = scoreValue[i];
    if (v.IsArray())
    {
    Value& col = v[0];
    temp = col.GetString();
    scores = atof(temp.c_str());
  }
  score->push_back(scores);
  }
}

string str=字符串.GetString();

int i=i.Getint();

prettyJson V7.1 使用的更多相关文章

  1. 安卓v7支持包下的ListView替代品————RecyclerView

    RecyclerView这个控件也出来很久了,相信大家也学习的差不多了,如果还没学习的,或许我可以带领大家体验一把这个艺术般的控件. 项目已经同步至github:https://github.com/ ...

  2. Atitit. Atiposter 发帖机 新特性 poster new feature   v7 q39

    Atitit. Atiposter 发帖机 新特性 poster new feature   v7 q39 V8   重构iocutilV4,use def iocFact...jettyUtil V ...

  3. Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds

    错误:Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds 错误提示就是我们限定了部署的时间导致的错 ...

  4. 【原创】JEECMS v6~v7任意文件上传漏洞(2)

    文章作者:rebeyond 受影响版本:v6~v7 漏洞说明: JEECMS是国内Java版开源网站内容管理系统(java cms.jsp cms)的简称.该系统基于java技术开发,继承其强大.稳定 ...

  5. 【原创】JEECMS v6~v7任意文件上传漏洞(1)

    文章作者:rebeyond 受影响版本:v6~v7 漏洞说明: JEECMS是国内Java版开源网站内容管理系统(java cms.jsp cms)的简称.该系统基于java技术开发,继承其强大.稳定 ...

  6. Server Tomcat v7.0 Server at localhost was unable to&amp;nbs 报错问题解决

    在eclipse启动tomcat时遇到超时45秒的问题: Server Tomcat v7.0 Server at localhost was unable to start within 45 se ...

  7. 转载文章-----Rational Rose2007(v7.0)下载地址、安装及激活详解教程(图)

    转载地址:http://www.cnblogs.com/leaven/p/3718361.html 最近需要画uml图,之前用的是Rose 2003版的,由于好久没进去了,结果发现原来的激活又失效了, ...

  8. Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds -----》myeclipse2015

    错误:Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds 错误提示就是我们限定了部署的时间导致的错 ...

  9. 80、Android Support v4、v7、v13的区别以及应用场景

    一.简介 在 Android 开发中,为了使用高版本API的新特性,需要添加额外的包来使用这些新特性,这就是 Android Support 包 二.分类 Android Support v4: 这个 ...

随机推荐

  1. (iOS)确保设置话筒模式成功 AudioSessionSetProperty

    本人编写过一个应用,须要把实时音频播放出来,而且要从话筒播放声音,为此,作下面操作: //Step 1: 初始化 AudioSessionInitialize(NULL,NULL, NULL, sel ...

  2. PHP 保留两位小数,且不四舍五入

    $value = '555.09988'; floor($value*100)/100;

  3. Redis之创建

    redis配置文件信息 public sealed class RedisConfigInfo { /// <summary> /// 可写的Redis链接地址 /// format:ip ...

  4. 利用css3的多背景图属性实现幻灯片切换效果

    css3里关于背景的属性增加了可以添加多背景图的特性,例如: .box{background: url(img/1.png),url(img/2.png),url(img/3.png);} 这段css ...

  5. CentOS6.x操作系统自带的 DM Multipath(DMMP)多路径软件配置说明。

    CentOS系统下的多路径软件是操作系统自带的 DM Multipath(DMMP)工具.------------------------------------------------------- ...

  6. 自动与因特网时间服务器同步 NTP 服务器 pool.ntp.org, 120.24.166.46 端口 123

    自动与因特网时间服务器同步   NTP 服务器 pool.ntp.org 海康提供的NTP服务器   120.24.166.46     端口  123

  7. Js 中的i++ 和 ++i 的区别

    首先碰见  i++ 和 ++i 会一脸蒙蔽 感觉没什么区别,都是相加  , 但是  输出的值是不同!!! 来奉上代码来进行比较 var i = 1; var a = i++; //a = 1; 此时i ...

  8. BZOJ——1012: [JSOI2008]最大数maxnumber || 洛谷—— P1198 [JSOI2008]最大数

    http://www.lydsy.com/JudgeOnline/problem.php?id=1012|| https://www.luogu.org/problem/show?pid=1198 T ...

  9. jni中调用java方法获取当前apk的签名文件md5值

    相应的java方法: void getsign(Context context) throws Exception { PackageInfo localPackageInfo = context.g ...

  10. nyoj 214 单调递增子序列(二) 【另类dp】

    单调递增子序列(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 ,a2...,an}(0<n<=100000),找出单调递增最长子序列.并求出其长度 ...