-
Notifications
You must be signed in to change notification settings - Fork 4
/
MenuParser.cpp
76 lines (59 loc) · 1.45 KB
/
MenuParser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "MenuParser.h"
#include <fstream>
#include <iostream>
Menu::Menu MenuParser::parse(std::string json)
{
Json::Reader reader;
Json::Value jsonObject;
Menu::Menu menu;
if (reader.parse(json, jsonObject)) {
auto menuTitle = jsonObject["title"];
if (menuTitle.isString())
{
menu.title = menuTitle.asString();
}
auto items = jsonObject["items"];
if (items.isArray()) {
for (auto one : items) {
Menu::Item item;
auto itemTitle = one["title"];
auto itemRC = one["resultCode"];
auto seconds = one["secondItems"];
if (itemTitle.isString())
{
item.title = itemTitle.asString();
}
if (itemRC.isInt()) {
item.resultCode = itemRC.asInt();
}
if (seconds.isArray())
{
for (auto second : seconds) {
Menu::SecondItem secondItem;
auto secondItemTitle = second["title"];
auto secondItemRC = second["resultCode"];
auto secondItemStatus = second["status"];
if (secondItemTitle.isString())
{
secondItem.title = secondItemTitle.asString();
}
if (secondItemRC.isInt()) {
secondItem.resultCode = secondItemRC.asInt();
}
if (secondItemStatus.isArray())
{
for (auto s : secondItemStatus) {
if (s.isString()) {
secondItem.status.push_back(s.asString());
}
}
}
item.secondItems.push_back(secondItem);
}
}
menu.items.push_back(item);
}
}
}
return menu;
}