NettyHttpCarInfo.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2021-11-04 15:59:10
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2021-11-15 13:47:13
  8. */
  9. #pragma once
  10. #include <iostream>
  11. #include <vector>
  12. #include "NettyHttpTrainInfo.h"
  13. #include "NettyHttpCarDevData.h"
  14. using namespace std;
  15. class NettyHttpCarInfo
  16. {
  17. public:
  18. std::string id;
  19. std::string pid;
  20. std::string label;
  21. NettyHttpTrainInfo attr;
  22. std::string attr1;
  23. std::string child;
  24. vector<NettyHttpCarDevData> children;
  25. public:
  26. NettyHttpCarInfo() {}
  27. ~NettyHttpCarInfo() {}
  28. /**
  29. * @description: json转换为对象
  30. * @param {Value&} object
  31. * @return {*}
  32. */
  33. bool jsonToObject(const rapidjson::Value& object){
  34. const auto end = object.MemberEnd();
  35. if(end == object.FindMember("id") || !object["id"].IsString()){
  36. return false;
  37. }else{
  38. id = object["id"].GetString();
  39. }
  40. // if(end == object.FindMember("pid") || !object["pid"].IsString()){
  41. // return false;
  42. // }else{
  43. // pid = object["pid"].GetString();
  44. // }
  45. if(end == object.FindMember("label") || !object["label"].IsString()){
  46. return false;
  47. }else{
  48. label = object["label"].GetString();
  49. }
  50. if(end == object.FindMember("attr") || !object["attr"].IsObject()){
  51. return false;
  52. }else{
  53. const rapidjson::Value& obj = object["attr"];
  54. if(!attr.jsonToObject(obj)){
  55. return false;
  56. }
  57. }
  58. if(end == object.FindMember("children")|| !(object["children"].IsArray())){
  59. return false;
  60. }else{
  61. const rapidjson::Value& objs = object["children"];
  62. for (size_t i = 0; i < objs.Size(); i++) {
  63. const rapidjson::Value& obj = objs[i];
  64. NettyHttpCarDevData data;
  65. if(!(data.jsonToObject(obj))){
  66. return false;
  67. }
  68. children.push_back(data);
  69. }
  70. }
  71. return true;
  72. }
  73. };