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/RecognizeQrCodeResult.h> 18 #include <json/json.h> 19 20 using namespace AlibabaCloud::Ocr; 21 using namespace AlibabaCloud::Ocr::Model; 22 RecognizeQrCodeResult()23RecognizeQrCodeResult::RecognizeQrCodeResult() : 24 ServiceResult() 25 {} 26 RecognizeQrCodeResult(const std::string & payload)27RecognizeQrCodeResult::RecognizeQrCodeResult(const std::string &payload) : 28 ServiceResult() 29 { 30 parse(payload); 31 } 32 ~RecognizeQrCodeResult()33RecognizeQrCodeResult::~RecognizeQrCodeResult() 34 {} 35 parse(const std::string & payload)36void RecognizeQrCodeResult::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 allElementsNode = dataNode["Elements"]["Element"]; 44 for (auto dataNodeElementsElement : allElementsNode) 45 { 46 Data::Element elementObject; 47 if(!dataNodeElementsElement["TaskId"].isNull()) 48 elementObject.taskId = dataNodeElementsElement["TaskId"].asString(); 49 if(!dataNodeElementsElement["ImageURL"].isNull()) 50 elementObject.imageURL = dataNodeElementsElement["ImageURL"].asString(); 51 auto allResultsNode = dataNodeElementsElement["Results"]["Result"]; 52 for (auto dataNodeElementsElementResultsResult : allResultsNode) 53 { 54 Data::Element::Result resultsObject; 55 if(!dataNodeElementsElementResultsResult["Label"].isNull()) 56 resultsObject.label = dataNodeElementsElementResultsResult["Label"].asString(); 57 if(!dataNodeElementsElementResultsResult["Suggestion"].isNull()) 58 resultsObject.suggestion = dataNodeElementsElementResultsResult["Suggestion"].asString(); 59 if(!dataNodeElementsElementResultsResult["Rate"].isNull()) 60 resultsObject.rate = std::stof(dataNodeElementsElementResultsResult["Rate"].asString()); 61 auto allQrCodesData = value["QrCodesData"]["QrCodeData"]; 62 for (auto value : allQrCodesData) 63 resultsObject.qrCodesData.push_back(value.asString()); 64 elementObject.results.push_back(resultsObject); 65 } 66 data_.elements.push_back(elementObject); 67 } 68 69 } 70 getData() const71RecognizeQrCodeResult::Data RecognizeQrCodeResult::getData()const 72 { 73 return data_; 74 } 75 76