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/RecognizeTableResult.h> 18 #include <json/json.h> 19 20 using namespace AlibabaCloud::Ocr; 21 using namespace AlibabaCloud::Ocr::Model; 22 RecognizeTableResult()23RecognizeTableResult::RecognizeTableResult() : 24 ServiceResult() 25 {} 26 RecognizeTableResult(const std::string & payload)27RecognizeTableResult::RecognizeTableResult(const std::string &payload) : 28 ServiceResult() 29 { 30 parse(payload); 31 } 32 ~RecognizeTableResult()33RecognizeTableResult::~RecognizeTableResult() 34 {} 35 parse(const std::string & payload)36void RecognizeTableResult::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 if(!dataNode["FileContent"].isNull()) 44 data_.fileContent = dataNode["FileContent"].asString(); 45 auto allTablesNode = dataNode["Tables"]["Table"]; 46 for (auto dataNodeTablesTable : allTablesNode) 47 { 48 Data::Table tableObject; 49 auto allTableRowsNode = dataNodeTablesTable["TableRows"]["TableRow"]; 50 for (auto dataNodeTablesTableTableRowsTableRow : allTableRowsNode) 51 { 52 Data::Table::TableRow tableRowsObject; 53 auto allTableColumnsNode = dataNodeTablesTableTableRowsTableRow["TableColumns"]["TableColumn"]; 54 for (auto dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn : allTableColumnsNode) 55 { 56 Data::Table::TableRow::TableColumn tableColumnsObject; 57 if(!dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["StartColumn"].isNull()) 58 tableColumnsObject.startColumn = std::stoi(dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["StartColumn"].asString()); 59 if(!dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["StartRow"].isNull()) 60 tableColumnsObject.startRow = std::stoi(dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["StartRow"].asString()); 61 if(!dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["EndColumn"].isNull()) 62 tableColumnsObject.endColumn = std::stoi(dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["EndColumn"].asString()); 63 if(!dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["EndRow"].isNull()) 64 tableColumnsObject.endRow = std::stoi(dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["EndRow"].asString()); 65 if(!dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["Height"].isNull()) 66 tableColumnsObject.height = std::stoi(dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["Height"].asString()); 67 if(!dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["Width"].isNull()) 68 tableColumnsObject.width = std::stoi(dataNodeTablesTableTableRowsTableRowTableColumnsTableColumn["Width"].asString()); 69 auto allTexts = value["Texts"]["Text"]; 70 for (auto value : allTexts) 71 tableColumnsObject.texts.push_back(value.asString()); 72 tableRowsObject.tableColumns.push_back(tableColumnsObject); 73 } 74 tableObject.tableRows.push_back(tableRowsObject); 75 } 76 auto allHead = value["Head"]["Head"]; 77 for (auto value : allHead) 78 tableObject.head.push_back(value.asString()); 79 auto allTail = value["Tail"]["Tail"]; 80 for (auto value : allTail) 81 tableObject.tail.push_back(value.asString()); 82 data_.tables.push_back(tableObject); 83 } 84 85 } 86 getData() const87RecognizeTableResult::Data RecognizeTableResult::getData()const 88 { 89 return data_; 90 } 91 92