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 17 #include <alibabacloud/ocr/model/RecognizeStampResult.h> 18 #include <json/json.h> 19 20 using namespace AlibabaCloud::Ocr; 21 using namespace AlibabaCloud::Ocr::Model; 22 RecognizeStampResult()23RecognizeStampResult::RecognizeStampResult() : 24 ServiceResult() 25 {} 26 RecognizeStampResult(const std::string & payload)27RecognizeStampResult::RecognizeStampResult(const std::string &payload) : 28 ServiceResult() 29 { 30 parse(payload); 31 } 32 ~RecognizeStampResult()33RecognizeStampResult::~RecognizeStampResult() 34 {} 35 parse(const std::string & payload)36void RecognizeStampResult::parse(const std::string &payload) 37 { 38 Json::Reader reader; 39 Json::Value value; 40 reader.parse(payload, value); 41 setRequestId(value["RequestId"].asString()); 42 auto dataNode = value["Data"]; 43 auto allResultsNode = dataNode["Results"]["ResultsItem"]; 44 for (auto dataNodeResultsResultsItem : allResultsNode) 45 { 46 Data::ResultsItem resultsItemObject; 47 auto allGeneralTextNode = dataNodeResultsResultsItem["GeneralText"]["GeneralTextItem"]; 48 for (auto dataNodeResultsResultsItemGeneralTextGeneralTextItem : allGeneralTextNode) 49 { 50 Data::ResultsItem::GeneralTextItem generalTextObject; 51 if(!dataNodeResultsResultsItemGeneralTextGeneralTextItem["Content"].isNull()) 52 generalTextObject.content = dataNodeResultsResultsItemGeneralTextGeneralTextItem["Content"].asString(); 53 if(!dataNodeResultsResultsItemGeneralTextGeneralTextItem["Confidence"].isNull()) 54 generalTextObject.confidence = std::stof(dataNodeResultsResultsItemGeneralTextGeneralTextItem["Confidence"].asString()); 55 resultsItemObject.generalText.push_back(generalTextObject); 56 } 57 auto roiNode = value["Roi"]; 58 if(!roiNode["Left"].isNull()) 59 resultsItemObject.roi.left = std::stoi(roiNode["Left"].asString()); 60 if(!roiNode["Top"].isNull()) 61 resultsItemObject.roi.top = std::stoi(roiNode["Top"].asString()); 62 if(!roiNode["Width"].isNull()) 63 resultsItemObject.roi.width = std::stoi(roiNode["Width"].asString()); 64 if(!roiNode["Height"].isNull()) 65 resultsItemObject.roi.height = std::stoi(roiNode["Height"].asString()); 66 auto textNode = value["Text"]; 67 if(!textNode["Content"].isNull()) 68 resultsItemObject.text.content = textNode["Content"].asString(); 69 if(!textNode["Confidence"].isNull()) 70 resultsItemObject.text.confidence = std::stof(textNode["Confidence"].asString()); 71 data_.results.push_back(resultsItemObject); 72 } 73 74 } 75 getData() const76RecognizeStampResult::Data RecognizeStampResult::getData()const 77 { 78 return data_; 79 } 80 81