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/RecognizeTaxiInvoiceResult.h>
18 #include <json/json.h>
19 
20 using namespace AlibabaCloud::Ocr;
21 using namespace AlibabaCloud::Ocr::Model;
22 
RecognizeTaxiInvoiceResult()23 RecognizeTaxiInvoiceResult::RecognizeTaxiInvoiceResult() :
24 	ServiceResult()
25 {}
26 
RecognizeTaxiInvoiceResult(const std::string & payload)27 RecognizeTaxiInvoiceResult::RecognizeTaxiInvoiceResult(const std::string &payload) :
28 	ServiceResult()
29 {
30 	parse(payload);
31 }
32 
~RecognizeTaxiInvoiceResult()33 RecognizeTaxiInvoiceResult::~RecognizeTaxiInvoiceResult()
34 {}
35 
parse(const std::string & payload)36 void RecognizeTaxiInvoiceResult::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 allInvoicesNode = dataNode["Invoices"]["Invoice"];
44 	for (auto dataNodeInvoicesInvoice : allInvoicesNode)
45 	{
46 		Data::Invoice invoiceObject;
47 		if(!dataNodeInvoicesInvoice["RotateType"].isNull())
48 			invoiceObject.rotateType = std::stoi(dataNodeInvoicesInvoice["RotateType"].asString());
49 		auto allItemsNode = dataNodeInvoicesInvoice["Items"]["Item"];
50 		for (auto dataNodeInvoicesInvoiceItemsItem : allItemsNode)
51 		{
52 			Data::Invoice::Item itemsObject;
53 			if(!dataNodeInvoicesInvoiceItemsItem["Text"].isNull())
54 				itemsObject.text = dataNodeInvoicesInvoiceItemsItem["Text"].asString();
55 			auto itemRoiNode = value["ItemRoi"];
56 			if(!itemRoiNode["Angle"].isNull())
57 				itemsObject.itemRoi.angle = std::stof(itemRoiNode["Angle"].asString());
58 			auto centerNode = itemRoiNode["Center"];
59 			if(!centerNode["X"].isNull())
60 				itemsObject.itemRoi.center.x = std::stof(centerNode["X"].asString());
61 			if(!centerNode["Y"].isNull())
62 				itemsObject.itemRoi.center.y = std::stof(centerNode["Y"].asString());
63 			auto sizeNode = itemRoiNode["Size"];
64 			if(!sizeNode["H"].isNull())
65 				itemsObject.itemRoi.size.h = std::stof(sizeNode["H"].asString());
66 			if(!sizeNode["W"].isNull())
67 				itemsObject.itemRoi.size.w = std::stof(sizeNode["W"].asString());
68 			invoiceObject.items.push_back(itemsObject);
69 		}
70 		auto invoiceRoiNode = value["InvoiceRoi"];
71 		if(!invoiceRoiNode["H"].isNull())
72 			invoiceObject.invoiceRoi.h = std::stof(invoiceRoiNode["H"].asString());
73 		if(!invoiceRoiNode["W"].isNull())
74 			invoiceObject.invoiceRoi.w = std::stof(invoiceRoiNode["W"].asString());
75 		if(!invoiceRoiNode["X"].isNull())
76 			invoiceObject.invoiceRoi.x = std::stof(invoiceRoiNode["X"].asString());
77 		if(!invoiceRoiNode["Y"].isNull())
78 			invoiceObject.invoiceRoi.y = std::stof(invoiceRoiNode["Y"].asString());
79 		data_.invoices.push_back(invoiceObject);
80 	}
81 
82 }
83 
getData() const84 RecognizeTaxiInvoiceResult::Data RecognizeTaxiInvoiceResult::getData()const
85 {
86 	return data_;
87 }
88 
89