RecognizeQuotaInvoiceResult.cc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/ocr/model/RecognizeQuotaInvoiceResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Ocr;
  19. using namespace AlibabaCloud::Ocr::Model;
  20. RecognizeQuotaInvoiceResult::RecognizeQuotaInvoiceResult() :
  21. ServiceResult()
  22. {}
  23. RecognizeQuotaInvoiceResult::RecognizeQuotaInvoiceResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. RecognizeQuotaInvoiceResult::~RecognizeQuotaInvoiceResult()
  29. {}
  30. void RecognizeQuotaInvoiceResult::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["Angle"].isNull())
  38. data_.angle = std::stol(dataNode["Angle"].asString());
  39. if(!dataNode["Height"].isNull())
  40. data_.height = std::stol(dataNode["Height"].asString());
  41. if(!dataNode["Width"].isNull())
  42. data_.width = std::stol(dataNode["Width"].asString());
  43. if(!dataNode["OrgHeight"].isNull())
  44. data_.orgHeight = std::stol(dataNode["OrgHeight"].asString());
  45. if(!dataNode["OrgWidth"].isNull())
  46. data_.orgWidth = std::stol(dataNode["OrgWidth"].asString());
  47. auto allKeyValueInfosNode = dataNode["KeyValueInfos"]["keyValueInfosItem"];
  48. for (auto dataNodeKeyValueInfoskeyValueInfosItem : allKeyValueInfosNode)
  49. {
  50. Data::KeyValueInfosItem keyValueInfosItemObject;
  51. if(!dataNodeKeyValueInfoskeyValueInfosItem["Key"].isNull())
  52. keyValueInfosItemObject.key = dataNodeKeyValueInfoskeyValueInfosItem["Key"].asString();
  53. if(!dataNodeKeyValueInfoskeyValueInfosItem["Value"].isNull())
  54. keyValueInfosItemObject.value = dataNodeKeyValueInfoskeyValueInfosItem["Value"].asString();
  55. if(!dataNodeKeyValueInfoskeyValueInfosItem["ValueScore"].isNull())
  56. keyValueInfosItemObject.valueScore = std::stof(dataNodeKeyValueInfoskeyValueInfosItem["ValueScore"].asString());
  57. auto allValuePositionsNode = dataNodeKeyValueInfoskeyValueInfosItem["ValuePositions"]["valuePositionsItem"];
  58. for (auto dataNodeKeyValueInfoskeyValueInfosItemValuePositionsvaluePositionsItem : allValuePositionsNode)
  59. {
  60. Data::KeyValueInfosItem::ValuePositionsItem valuePositionsObject;
  61. if(!dataNodeKeyValueInfoskeyValueInfosItemValuePositionsvaluePositionsItem["X"].isNull())
  62. valuePositionsObject.x = std::stol(dataNodeKeyValueInfoskeyValueInfosItemValuePositionsvaluePositionsItem["X"].asString());
  63. if(!dataNodeKeyValueInfoskeyValueInfosItemValuePositionsvaluePositionsItem["Y"].isNull())
  64. valuePositionsObject.y = std::stol(dataNodeKeyValueInfoskeyValueInfosItemValuePositionsvaluePositionsItem["Y"].asString());
  65. keyValueInfosItemObject.valuePositions.push_back(valuePositionsObject);
  66. }
  67. data_.keyValueInfos.push_back(keyValueInfosItemObject);
  68. }
  69. auto contentNode = dataNode["Content"];
  70. if(!contentNode["SumAmount"].isNull())
  71. data_.content.sumAmount = contentNode["SumAmount"].asString();
  72. if(!contentNode["InvoiceCode"].isNull())
  73. data_.content.invoiceCode = contentNode["InvoiceCode"].asString();
  74. if(!contentNode["InvoiceNo"].isNull())
  75. data_.content.invoiceNo = contentNode["InvoiceNo"].asString();
  76. if(!contentNode["InvoiceAmount"].isNull())
  77. data_.content.invoiceAmount = contentNode["InvoiceAmount"].asString();
  78. if(!contentNode["InvoiceDetails"].isNull())
  79. data_.content.invoiceDetails = contentNode["InvoiceDetails"].asString();
  80. if(!value["Code"].isNull())
  81. code_ = value["Code"].asString();
  82. if(!value["Message"].isNull())
  83. message_ = value["Message"].asString();
  84. }
  85. std::string RecognizeQuotaInvoiceResult::getMessage()const
  86. {
  87. return message_;
  88. }
  89. RecognizeQuotaInvoiceResult::Data RecognizeQuotaInvoiceResult::getData()const
  90. {
  91. return data_;
  92. }
  93. std::string RecognizeQuotaInvoiceResult::getCode()const
  94. {
  95. return code_;
  96. }