bool MyLottery::LoadJson(){
m_lotteryItemMap.clear();
rapidjson::Document doc;
std::string data = FileUtils::getInstance()->getStringFromFile("lottery.json");
doc.Parse(data.c_str());
if (doc.HasParseError())
return false;
rapidjson::Value &LotteryId = doc["LotteryId"];
rapidjson::Value &lotteryItemInfo = doc["LotteryItems"];
if (!lotteryItemInfo.Empty())
{
size_t LotteryItemCount = lotteryItemInfo.Size();
for (size_t i = 0; i < LotteryItemCount; ++i)
{
rapidjson::Value &lotteryItemValue = lotteryItemInfo[i];
LotteryItem lottery;
if (lotteryItemValue.HasMember("ItemId"))
lottery.ItemId = lotteryItemValue["ItemId"].GetInt();
else
continue;
if (lotteryItemValue.HasMember("LotteryItemId"))
lottery.LotteryItemId = lotteryItemValue["LotteryItemId"].GetInt();
if (lotteryItemValue.HasMember("ItemName"))
lottery.ItemName = lotteryItemValue["ItemName"].GetString();
if (lotteryItemValue.HasMember("ItemCount"))
lottery.ItemCount = lotteryItemValue["ItemCount"].GetInt();
if (lotteryItemValue.HasMember("ImagePath"))
lottery.ImagePath = lotteryItemValue["ImagePath"].GetString();
if (lotteryItemValue.HasMember("ItemType"))
lottery.ItemType = lotteryItemValue["ItemType"].GetInt();
m_lotteryItemMap[lottery.ItemId] = lottery;
}
}
}
{
"LotteryId": 22,
"NotHitItem": 186,
"LotteryItemsImg": "lottery/lottery_items.png",
"RuleImg": "lottery/rule_img.png",
"Opportunities": "剩余1次",
"LotteryItems": [
{
"ItemId": 21,
"ItemType": 1,
"LotteryItemId": 187,
"ItemName": "1000金蛋",
"ItemCount": 1000,
"ImagePath": "coin_lottery.png"
},
{
"ItemId": 22,
"ItemType": 0,
"LotteryItemId": 186,
"ItemName": "谢谢参与",
"ItemCount": 0,
"ImagePath": "back_btn.png"
},
{
"ItemId": 23,
"ItemType": 2,
"LotteryItemId": 192,
"ItemName": "200元话费",
"AwardId": 30,
"ItemCount": 18,
"ImagePath": "phone_lottery.png"
},
{
"ItemId": 24,
"ItemType": 1,
"LotteryItemId": 188,
"ItemName": "10金蛋",
"ItemCount": 2000,
"ImagePath": "coin_lottery.png"
},
{
"ItemId": 25,
"ItemType": 1,
"LotteryItemId": 191,
"ItemName": "5元话费",
"ItemCount": 100,
"ImagePath": "phone_lottery.png"
},
{
"ItemId": 26,
"ItemType": 1,
"LotteryItemId": 189,
"ItemName": "200金蛋",
"ItemCount": 5000,
"ImagePath": "coin_lottery.png"
},
{
"ItemId": 27,
"ItemType": 1,
"LotteryItemId": 190,
"ItemName": "1元话费",
"ItemCount": 50,
"ImagePath": "phone_lottery.png"
},
{
"ItemId": 28,
"ItemType": 2,
"LotteryItemId": 194,
"ItemName": "100奖券",
"ItemCount": 1,
"ImagePath": "prop2.png"
}
]
}
json文件的格式