头文件

#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. style="background-image: url(__HOMEPAGE__/views/IMJ2V2/images/banner2.jpg)"

    style="background-image: url(__HOMEPAGE__/views/IMJ2V2/images/banner2.jpg)" 一.问题 backgroun ...

  2. Linux下清除系统日志方法

    摘要:相信大家都是用过Windows的人.对于Windows下饱受诟病的各种垃圾文件都需要自己想办法删除,不然你的系统将会变得越来越大,越来越迟钝!windows怎么清理垃圾相信大家都知道的,那么li ...

  3. 85.explicit作用

    #include <iostream> using namespace std; class myclass { public: int num; public: explicit myc ...

  4. Weka中数据挖掘与机器学习系列之为什么要写Weka这一系列学习笔记?(一)

    本人正值科研之年,同时也在使用Weka来做相关数据挖掘和机器学习的论文工作. 为了记录自己的学习历程,也便于分享和带领入门的你们.废话不多说,直接上干货!

  5. HTTP协议学习,post于get;用Fiddler测试请求

    转载 收藏于网络 1.简介: HTTP协议:Hypertext transfer protocol 超文本 传输 协议 它是TCP/IP协议集中的一个运用层协议. 用于定义WEB浏览器和WEB服务器之 ...

  6. DevExpress Report打印边距越界问题

    DevExpress  Report Print的时候,出现这样的问题:one or more margins are set outside the printable area of the pa ...

  7. 学习参考《TensorFlow深度学习》高清中文版PDF+英文版PDF+源代码

    我们知道,TensorFlow是比较流行的深度学习框架,除了看手册文档外,推荐大家看看<Tensorflow深度学习>,共分5方面内容:基础知识.关键模块.算法模型.内核揭秘.生态发展.前 ...

  8. python note #3

    Hello, guys! I found it pretty difficult to get my content according to my key words. So in this not ...

  9. @MapperScan 和 @ComponentScan 区别

    1.首先@MapperScan和@ComponentScan都是扫描包 2.@ComponentScan是组件扫描注解,用来扫描@Controller  @Service  @Repository这类 ...

  10. valgrind的说明使用和原理

    编译 #gcc -g -o test test.c 内存检查#valgrind --tool=memcheck --leak-check=yes --show-reachable=yes ./test ...