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/RecognizePoiNameResult.h>
18 #include <json/json.h>
19 
20 using namespace AlibabaCloud::Ocr;
21 using namespace AlibabaCloud::Ocr::Model;
22 
RecognizePoiNameResult()23 RecognizePoiNameResult::RecognizePoiNameResult() :
24 	ServiceResult()
25 {}
26 
RecognizePoiNameResult(const std::string & payload)27 RecognizePoiNameResult::RecognizePoiNameResult(const std::string &payload) :
28 	ServiceResult()
29 {
30 	parse(payload);
31 }
32 
~RecognizePoiNameResult()33 RecognizePoiNameResult::~RecognizePoiNameResult()
34 {}
35 
parse(const std::string & payload)36 void RecognizePoiNameResult::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 allSignboardsNode = dataNode["Signboards"]["SignboardsItem"];
44 	for (auto dataNodeSignboardsSignboardsItem : allSignboardsNode)
45 	{
46 		Data::SignboardsItem signboardsItemObject;
47 		auto allTextsNode = dataNodeSignboardsSignboardsItem["Texts"]["TextsItem"];
48 		for (auto dataNodeSignboardsSignboardsItemTextsTextsItem : allTextsNode)
49 		{
50 			Data::SignboardsItem::TextsItem textsObject;
51 			if(!dataNodeSignboardsSignboardsItemTextsTextsItem["Label"].isNull())
52 				textsObject.label = dataNodeSignboardsSignboardsItemTextsTextsItem["Label"].asString();
53 			if(!dataNodeSignboardsSignboardsItemTextsTextsItem["Score"].isNull())
54 				textsObject.score = std::stof(dataNodeSignboardsSignboardsItemTextsTextsItem["Score"].asString());
55 			if(!dataNodeSignboardsSignboardsItemTextsTextsItem["Tag"].isNull())
56 				textsObject.tag = dataNodeSignboardsSignboardsItemTextsTextsItem["Tag"].asString();
57 			if(!dataNodeSignboardsSignboardsItemTextsTextsItem["Type"].isNull())
58 				textsObject.type = dataNodeSignboardsSignboardsItemTextsTextsItem["Type"].asString();
59 			auto allPoints = value["Points"]["Points"];
60 			for (auto value : allPoints)
61 				textsObject.points.push_back(value.asString());
62 			signboardsItemObject.texts.push_back(textsObject);
63 		}
64 		data_.signboards.push_back(signboardsItemObject);
65 	}
66 	auto summaryNode = dataNode["Summary"];
67 	if(!summaryNode["Brand"].isNull())
68 		data_.summary.brand = summaryNode["Brand"].asString();
69 	if(!summaryNode["Score"].isNull())
70 		data_.summary.score = std::stof(summaryNode["Score"].asString());
71 
72 }
73 
getData() const74 RecognizePoiNameResult::Data RecognizePoiNameResult::getData()const
75 {
76 	return data_;
77 }
78 
79