/* * @Description: * @Version: 1.0 * @Autor: lishengyin * @Date: 2021-11-18 09:32:16 * @LastEditors: lishengyin * @LastEditTime: 2021-11-29 09:14:48 */ #pragma once #include #include #include #include #include #include using namespace std; class Crowdedness { public: int timeType; int cdLevel1Min; int cdLevel1Max; int cdLevel2Min; int cdLevel2Max; int cdLevel3Min; int cdLevel3Max; public: Crowdedness() {} ~Crowdedness() {} /** * @description: json转换为object * @param {Value&} object * @return {*} */ bool jsonToObject(const rapidjson::Value& object){ const auto end = object.MemberEnd(); if(end == object.FindMember("timeType") || !object["timeType"].IsString()){ return false; }else{ timeType = atoi(object["timeType"].GetString()); } if(end == object.FindMember("cdLevel1Min") || !object["cdLevel1Min"].IsString()){ return false; }else{ cdLevel1Min = atoi(object["cdLevel1Min"].GetString()); } if(end == object.FindMember("cdLevel1Max") || !object["cdLevel1Max"].IsString()){ return false; }else{ cdLevel1Max = atoi(object["cdLevel1Max"].GetString()); } if(end == object.FindMember("cdLevel2Min") || !object["cdLevel2Min"].IsString()){ return false; }else{ cdLevel2Min = atoi(object["cdLevel2Min"].GetString()); } if(end == object.FindMember("cdLevel2Max") || !object["cdLevel2Max"].IsString()){ return false; }else{ cdLevel2Max = atoi(object["cdLevel2Max"].GetString()); } if(end == object.FindMember("cdLevel3Min") || !object["cdLevel3Min"].IsString()){ return false; }else{ cdLevel3Min = atoi(object["cdLevel3Min"].GetString()); } if(end == object.FindMember("cdLevel3Max") || !object["cdLevel3Max"].IsString()){ return false; }else{ cdLevel3Max = atoi(object["cdLevel3Max"].GetString()); } return true; } }; class CrowdednessConfig { public: vector CrowdednessVector; public: CrowdednessConfig() {} ~CrowdednessConfig() {} /** * @description: json转换为object * @param {string&} json * @return {*} */ bool jsonToObject(const std::string& json) { rapidjson::Document doc; if (doc.Parse(json.c_str()).HasParseError()) { return false; } if(doc.IsArray()) { const rapidjson::Value& objs = doc; for(int i = 0; i < (int)(objs.Size()); i++){ Crowdedness crowdedness; if(!crowdedness.jsonToObject(objs[i])){ return false; } CrowdednessVector.push_back(crowdedness); } }else{ return false; } return true; } };