BatchTranslateForHtmlResult.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/anytrans/model/BatchTranslateForHtmlResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::AnyTrans;
  19. using namespace AlibabaCloud::AnyTrans::Model;
  20. BatchTranslateForHtmlResult::BatchTranslateForHtmlResult() :
  21. ServiceResult()
  22. {}
  23. BatchTranslateForHtmlResult::BatchTranslateForHtmlResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. BatchTranslateForHtmlResult::~BatchTranslateForHtmlResult()
  29. {}
  30. void BatchTranslateForHtmlResult::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. auto alltranslationListNode = dataNode["translationList"]["translationListItem"];
  38. for (auto dataNodetranslationListtranslationListItem : alltranslationListNode)
  39. {
  40. Data::TranslationListItem translationListItemObject;
  41. if(!dataNodetranslationListtranslationListItem["code"].isNull())
  42. translationListItemObject.code = std::stol(dataNodetranslationListtranslationListItem["code"].asString());
  43. if(!dataNodetranslationListtranslationListItem["message"].isNull())
  44. translationListItemObject.message = dataNodetranslationListtranslationListItem["message"].asString();
  45. if(!dataNodetranslationListtranslationListItem["index"].isNull())
  46. translationListItemObject.index = dataNodetranslationListtranslationListItem["index"].asString();
  47. if(!dataNodetranslationListtranslationListItem["translation"].isNull())
  48. translationListItemObject.translation = dataNodetranslationListtranslationListItem["translation"].asString();
  49. auto usageNode = value["usage"];
  50. if(!usageNode["inputTokens"].isNull())
  51. translationListItemObject.usage.inputTokens = std::stol(usageNode["inputTokens"].asString());
  52. if(!usageNode["outputTokens"].isNull())
  53. translationListItemObject.usage.outputTokens = std::stol(usageNode["outputTokens"].asString());
  54. if(!usageNode["totalTokens"].isNull())
  55. translationListItemObject.usage.totalTokens = std::stol(usageNode["totalTokens"].asString());
  56. data_.translationList.push_back(translationListItemObject);
  57. }
  58. if(!value["code"].isNull())
  59. code_ = value["code"].asString();
  60. if(!value["message"].isNull())
  61. message_ = value["message"].asString();
  62. if(!value["requestId"].isNull())
  63. requestId_ = value["requestId"].asString();
  64. if(!value["success"].isNull())
  65. success_ = value["success"].asString() == "true";
  66. if(!value["httpStatusCode"].isNull())
  67. httpStatusCode_ = value["httpStatusCode"].asString();
  68. }
  69. std::string BatchTranslateForHtmlResult::getMessage()const
  70. {
  71. return message_;
  72. }
  73. std::string BatchTranslateForHtmlResult::getRequestId()const
  74. {
  75. return requestId_;
  76. }
  77. std::string BatchTranslateForHtmlResult::getHttpStatusCode()const
  78. {
  79. return httpStatusCode_;
  80. }
  81. BatchTranslateForHtmlResult::Data BatchTranslateForHtmlResult::getData()const
  82. {
  83. return data_;
  84. }
  85. std::string BatchTranslateForHtmlResult::getCode()const
  86. {
  87. return code_;
  88. }
  89. bool BatchTranslateForHtmlResult::getSuccess()const
  90. {
  91. return success_;
  92. }