日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

prettyJson V7.1 使用

發布時間:2024/4/17 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 prettyJson V7.1 使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

頭文件

#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=0;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);//vectorroot.AddMember("vector", everyLoop, allocator);//introot.AddMember("int", i, allocator);StringBuffer buffer;Writer<StringBuffer> writer(buffer);root.Accept(writer);strJson = buffer.GetString();

?

讀取json

Document doc;doc.Parse<0>(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();

?

轉載于:https://www.cnblogs.com/ye-ming/p/8797833.html

總結

以上是生活随笔為你收集整理的prettyJson V7.1 使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。