前端之家收集整理的这篇文章主要介绍了
rapidjson解析数据,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#include "json/rapidjson.h"
#include "json/document.h"
using namespace rapidjson;
string strPath = FileUtils::getInstance()->fullPathForFilename("friend.json");
long size;
unsigned char* ch = FileUtils::getInstance()->getFileData(strPath,"r",&size);
string data = string((const char*)ch,size);
Document m_doc;
m_doc.Parse<0>(data.c_str());
if (m_doc.HasParseError())
{
log("GetParaseError:%s\n",m_doc.GetParseError());
}
for (int i = 0; i < m_doc.Size(); i++)
{
rapidjson::Value& item = m_doc[(unsigned int)i];
int rank = item["rank"].GetInt();
log("%d",rank);
auto name = item["name"].GetString();
log("%s",name);
int score = item["score"].GetInt();
log("%d",score);
int propType = item["propType"].GetInt();
log("%d",propType);
auto listItem = UserListItem::create(this);
listItem->initInfo(name,rank,score);
listView->pushBackCustomItem(listItem);
log("------------");
}
[
{"rank" : 1,"name" : "小鬼","score" : 50,"propType" : 1},{"rank" : 2,"name" : "小妹","score" : 100,"propType" : 2},{"rank" : 3,"name" : "小刚",{"rank" : 4,"name" : "小宏",{"rank" : 5,"name" : "小红","propType" : 1}]
原文链接:https://www.f2er.com/json/289283.html