.h
#pragma once
#include <string.h>
#include "json/json.h"
typedef struct ResultModel
{
std::string sGameDate;
std::string sLeague;
std::string sHomeTeam;
std::string sVisitTeam;
std::string sHomeScore_Half;
std::string sVisitScore_Half;
std::string sHomeScore_All;
std::string sVisitScore_All;
};
class CollectLogic {
public:
CollectLogic();
void LoadData();
private:
std::vector<ResultModel*> mData;
};
.cpp
void CollectLogic::LoadData()
{
for (size_t i = 0; i < mData.size(); i++)
{
ResultModel *pResultModel = mData[i];
delete pResultModel;
pResultModel = NULL;
}
mData.clear();
BasicConfig Config;
if (JsonUtil::load_json_config("resultData.json", Config.__json) != 0)
{
return;
}
for (Json::Value::iterator itor = Config.__json.begin(); itor != Config.__json.end(); ++itor)
{
Json::Value& json = *itor;
ResultModel *pResultModel = new ResultModel();
pResultModel->sGameDate = json["GameDate"].asCString();
pResultModel->sHomeScore_All = json["League"].asCString();
pResultModel->sHomeScore_Half = json["HomeTeam"].asCString();
pResultModel->sHomeTeam = json["VisitTeam"].asCString();
pResultModel->sLeague = json["HomeScore_Half"].asCString();
pResultModel->sVisitScore_All = json["VisitScore_Half"].asCString();
pResultModel->sVisitScore_Half = json["HomeScore_All"].asCString();
pResultModel->sVisitTeam = json["VisitScore_All"].asCString();
mData.push_back(pResultModel);
}
}
资源信息有json库