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/RecognizeAccountPageResult.h>
18 #include <json/json.h>
19 
20 using namespace AlibabaCloud::Ocr;
21 using namespace AlibabaCloud::Ocr::Model;
22 
RecognizeAccountPageResult()23 RecognizeAccountPageResult::RecognizeAccountPageResult() :
24 	ServiceResult()
25 {}
26 
RecognizeAccountPageResult(const std::string & payload)27 RecognizeAccountPageResult::RecognizeAccountPageResult(const std::string &payload) :
28 	ServiceResult()
29 {
30 	parse(payload);
31 }
32 
~RecognizeAccountPageResult()33 RecognizeAccountPageResult::~RecognizeAccountPageResult()
34 {}
35 
parse(const std::string & payload)36 void RecognizeAccountPageResult::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["Angle"].isNull())
44 		data_.angle = std::stof(dataNode["Angle"].asString());
45 	if(!dataNode["Name"].isNull())
46 		data_.name = dataNode["Name"].asString();
47 	if(!dataNode["Gender"].isNull())
48 		data_.gender = dataNode["Gender"].asString();
49 	if(!dataNode["Relation"].isNull())
50 		data_.relation = dataNode["Relation"].asString();
51 	if(!dataNode["BirthPlace"].isNull())
52 		data_.birthPlace = dataNode["BirthPlace"].asString();
53 	if(!dataNode["Nationality"].isNull())
54 		data_.nationality = dataNode["Nationality"].asString();
55 	if(!dataNode["NativePlace"].isNull())
56 		data_.nativePlace = dataNode["NativePlace"].asString();
57 	if(!dataNode["BirthDate"].isNull())
58 		data_.birthDate = dataNode["BirthDate"].asString();
59 	if(!dataNode["IDNumber"].isNull())
60 		data_.iDNumber = dataNode["IDNumber"].asString();
61 	auto allInvalidStampAreasNode = dataNode["InvalidStampAreas"]["InvalidStampArea"];
62 	for (auto dataNodeInvalidStampAreasInvalidStampArea : allInvalidStampAreasNode)
63 	{
64 		Data::InvalidStampArea invalidStampAreaObject;
65 		if(!dataNodeInvalidStampAreasInvalidStampArea["Left"].isNull())
66 			invalidStampAreaObject.left = std::stoi(dataNodeInvalidStampAreasInvalidStampArea["Left"].asString());
67 		if(!dataNodeInvalidStampAreasInvalidStampArea["Top"].isNull())
68 			invalidStampAreaObject.top = std::stoi(dataNodeInvalidStampAreasInvalidStampArea["Top"].asString());
69 		if(!dataNodeInvalidStampAreasInvalidStampArea["Height"].isNull())
70 			invalidStampAreaObject.height = std::stoi(dataNodeInvalidStampAreasInvalidStampArea["Height"].asString());
71 		if(!dataNodeInvalidStampAreasInvalidStampArea["Width"].isNull())
72 			invalidStampAreaObject.width = std::stoi(dataNodeInvalidStampAreasInvalidStampArea["Width"].asString());
73 		data_.invalidStampAreas.push_back(invalidStampAreaObject);
74 	}
75 	auto allUndertakeStampAreasNode = dataNode["UndertakeStampAreas"]["UndertakeStampArea"];
76 	for (auto dataNodeUndertakeStampAreasUndertakeStampArea : allUndertakeStampAreasNode)
77 	{
78 		Data::UndertakeStampArea undertakeStampAreaObject;
79 		if(!dataNodeUndertakeStampAreasUndertakeStampArea["Left"].isNull())
80 			undertakeStampAreaObject.left = std::stoi(dataNodeUndertakeStampAreasUndertakeStampArea["Left"].asString());
81 		if(!dataNodeUndertakeStampAreasUndertakeStampArea["Top"].isNull())
82 			undertakeStampAreaObject.top = std::stoi(dataNodeUndertakeStampAreasUndertakeStampArea["Top"].asString());
83 		if(!dataNodeUndertakeStampAreasUndertakeStampArea["Height"].isNull())
84 			undertakeStampAreaObject.height = std::stoi(dataNodeUndertakeStampAreasUndertakeStampArea["Height"].asString());
85 		if(!dataNodeUndertakeStampAreasUndertakeStampArea["Width"].isNull())
86 			undertakeStampAreaObject.width = std::stoi(dataNodeUndertakeStampAreasUndertakeStampArea["Width"].asString());
87 		data_.undertakeStampAreas.push_back(undertakeStampAreaObject);
88 	}
89 	auto allRegisterStampAreasNode = dataNode["RegisterStampAreas"]["RegisterStampArea"];
90 	for (auto dataNodeRegisterStampAreasRegisterStampArea : allRegisterStampAreasNode)
91 	{
92 		Data::RegisterStampArea registerStampAreaObject;
93 		if(!dataNodeRegisterStampAreasRegisterStampArea["Left"].isNull())
94 			registerStampAreaObject.left = std::stoi(dataNodeRegisterStampAreasRegisterStampArea["Left"].asString());
95 		if(!dataNodeRegisterStampAreasRegisterStampArea["Top"].isNull())
96 			registerStampAreaObject.top = std::stoi(dataNodeRegisterStampAreasRegisterStampArea["Top"].asString());
97 		if(!dataNodeRegisterStampAreasRegisterStampArea["Height"].isNull())
98 			registerStampAreaObject.height = std::stoi(dataNodeRegisterStampAreasRegisterStampArea["Height"].asString());
99 		if(!dataNodeRegisterStampAreasRegisterStampArea["Width"].isNull())
100 			registerStampAreaObject.width = std::stoi(dataNodeRegisterStampAreasRegisterStampArea["Width"].asString());
101 		data_.registerStampAreas.push_back(registerStampAreaObject);
102 	}
103 	auto allOtherStampAreasNode = dataNode["OtherStampAreas"]["OtherStampArea"];
104 	for (auto dataNodeOtherStampAreasOtherStampArea : allOtherStampAreasNode)
105 	{
106 		Data::OtherStampArea otherStampAreaObject;
107 		if(!dataNodeOtherStampAreasOtherStampArea["Left"].isNull())
108 			otherStampAreaObject.left = std::stoi(dataNodeOtherStampAreasOtherStampArea["Left"].asString());
109 		if(!dataNodeOtherStampAreasOtherStampArea["Top"].isNull())
110 			otherStampAreaObject.top = std::stoi(dataNodeOtherStampAreasOtherStampArea["Top"].asString());
111 		if(!dataNodeOtherStampAreasOtherStampArea["Height"].isNull())
112 			otherStampAreaObject.height = std::stoi(dataNodeOtherStampAreasOtherStampArea["Height"].asString());
113 		if(!dataNodeOtherStampAreasOtherStampArea["Width"].isNull())
114 			otherStampAreaObject.width = std::stoi(dataNodeOtherStampAreasOtherStampArea["Width"].asString());
115 		data_.otherStampAreas.push_back(otherStampAreaObject);
116 	}
117 	auto titleAreaNode = dataNode["TitleArea"];
118 	if(!titleAreaNode["Left"].isNull())
119 		data_.titleArea.left = std::stoi(titleAreaNode["Left"].asString());
120 	if(!titleAreaNode["Top"].isNull())
121 		data_.titleArea.top = std::stoi(titleAreaNode["Top"].asString());
122 	if(!titleAreaNode["Height"].isNull())
123 		data_.titleArea.height = std::stoi(titleAreaNode["Height"].asString());
124 	if(!titleAreaNode["Width"].isNull())
125 		data_.titleArea.width = std::stoi(titleAreaNode["Width"].asString());
126 
127 }
128 
getData() const129 RecognizeAccountPageResult::Data RecognizeAccountPageResult::getData()const
130 {
131 	return data_;
132 }
133 
134