123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /*
- * @Description:
- * @Version: 1.0
- * @Autor: lishengyin
- * @Date: 2021-11-04 15:59:10
- * @LastEditors: lishengyin
- * @LastEditTime: 2021-11-15 13:47:13
- */
- #pragma once
- #include <iostream>
- #include <vector>
- #include "NettyHttpTrainInfo.h"
- #include "NettyHttpCarDevData.h"
- using namespace std;
- class NettyHttpCarInfo
- {
- public:
- std::string id;
- std::string pid;
- std::string label;
- NettyHttpTrainInfo attr;
- std::string attr1;
- std::string child;
- vector<NettyHttpCarDevData> children;
- public:
- NettyHttpCarInfo() {}
- ~NettyHttpCarInfo() {}
- /**
- * @description: json转换为对象
- * @param {Value&} object
- * @return {*}
- */
- bool jsonToObject(const rapidjson::Value& object){
- const auto end = object.MemberEnd();
- if(end == object.FindMember("id") || !object["id"].IsString()){
- return false;
- }else{
- id = object["id"].GetString();
- }
- // if(end == object.FindMember("pid") || !object["pid"].IsString()){
- // return false;
- // }else{
- // pid = object["pid"].GetString();
- // }
- if(end == object.FindMember("label") || !object["label"].IsString()){
- return false;
- }else{
- label = object["label"].GetString();
- }
- if(end == object.FindMember("attr") || !object["attr"].IsObject()){
- return false;
- }else{
- const rapidjson::Value& obj = object["attr"];
- if(!attr.jsonToObject(obj)){
- return false;
- }
- }
- if(end == object.FindMember("children")|| !(object["children"].IsArray())){
- return false;
- }else{
- const rapidjson::Value& objs = object["children"];
- for (size_t i = 0; i < objs.Size(); i++) {
- const rapidjson::Value& obj = objs[i];
- NettyHttpCarDevData data;
- if(!(data.jsonToObject(obj))){
- return false;
- }
- children.push_back(data);
- }
- }
- return true;
- }
- };
|