SearchBodyResult.cc 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/vcs/model/SearchBodyResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Vcs;
  19. using namespace AlibabaCloud::Vcs::Model;
  20. SearchBodyResult::SearchBodyResult() :
  21. ServiceResult()
  22. {}
  23. SearchBodyResult::SearchBodyResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. SearchBodyResult::~SearchBodyResult()
  29. {}
  30. void SearchBodyResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto dataNode = value["Data"];
  37. if(!dataNode["PageNo"].isNull())
  38. data_.pageNo = std::stoi(dataNode["PageNo"].asString());
  39. if(!dataNode["PageSize"].isNull())
  40. data_.pageSize = std::stoi(dataNode["PageSize"].asString());
  41. if(!dataNode["TotalCount"].isNull())
  42. data_.totalCount = std::stoi(dataNode["TotalCount"].asString());
  43. if(!dataNode["TotalPage"].isNull())
  44. data_.totalPage = std::stoi(dataNode["TotalPage"].asString());
  45. auto allRecordsNode = dataNode["Records"]["Record"];
  46. for (auto dataNodeRecordsRecord : allRecordsNode)
  47. {
  48. Data::Record recordObject;
  49. if(!dataNodeRecordsRecord["GbId"].isNull())
  50. recordObject.gbId = dataNodeRecordsRecord["GbId"].asString();
  51. if(!dataNodeRecordsRecord["ImageUrl"].isNull())
  52. recordObject.imageUrl = dataNodeRecordsRecord["ImageUrl"].asString();
  53. if(!dataNodeRecordsRecord["LeftTopX"].isNull())
  54. recordObject.leftTopX = std::stof(dataNodeRecordsRecord["LeftTopX"].asString());
  55. if(!dataNodeRecordsRecord["LeftTopY"].isNull())
  56. recordObject.leftTopY = std::stof(dataNodeRecordsRecord["LeftTopY"].asString());
  57. if(!dataNodeRecordsRecord["RightBottomX"].isNull())
  58. recordObject.rightBottomX = std::stof(dataNodeRecordsRecord["RightBottomX"].asString());
  59. if(!dataNodeRecordsRecord["RightBottomY"].isNull())
  60. recordObject.rightBottomY = std::stof(dataNodeRecordsRecord["RightBottomY"].asString());
  61. if(!dataNodeRecordsRecord["Score"].isNull())
  62. recordObject.score = std::stof(dataNodeRecordsRecord["Score"].asString());
  63. if(!dataNodeRecordsRecord["TargetImageUrl"].isNull())
  64. recordObject.targetImageUrl = dataNodeRecordsRecord["TargetImageUrl"].asString();
  65. data_.records.push_back(recordObject);
  66. }
  67. if(!value["Code"].isNull())
  68. code_ = value["Code"].asString();
  69. if(!value["Message"].isNull())
  70. message_ = value["Message"].asString();
  71. }
  72. std::string SearchBodyResult::getMessage()const
  73. {
  74. return message_;
  75. }
  76. SearchBodyResult::Data SearchBodyResult::getData()const
  77. {
  78. return data_;
  79. }
  80. std::string SearchBodyResult::getCode()const
  81. {
  82. return code_;
  83. }