-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathjsonparser.h
102 lines (91 loc) · 2.09 KB
/
jsonparser.h
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <string>
#include <vector>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <vdr/plugin.h>
#ifndef __JSONPARSER_H
#define __JSONPARSER_H
class JsonBase
{
private:
int _type;
public:
JsonBase(int type);
~JsonBase();
bool IsObject();
bool IsValue();
bool IsBasicValue();
bool IsArray();
};
class JsonValue : public JsonBase
{
private:
std::string _identifier;
JsonBase* _value;
public:
JsonValue(std::string identifier);
~JsonValue();
std::string Identifier();
void Value(JsonBase* value);
JsonBase* Value();
};
class JsonBasicValue : public JsonBase
{
private:
std::string _str;
double _double;
bool _bool;
int _type;
public:
JsonBasicValue(std::string value);
JsonBasicValue(double value);
JsonBasicValue(bool value);
~JsonBasicValue();
bool IsString();
bool IsBool();
bool IsDouble();
std::string ValueAsString();
double ValueAsDouble();
bool ValueAsBool();
};
class JsonArray : public JsonBase
{
private:
std::vector< JsonBase* > _items;
public:
JsonArray();
~JsonArray();
void AddItem(JsonBase* item);
JsonBase* GetItem(int i);
int CountItem();
};
class JsonObject : public JsonBase
{
private:
std::vector< JsonValue* > _items;
public:
JsonObject();
~JsonObject();
void AddItem(JsonValue* item);
JsonValue* GetItem(int i);
JsonValue* GetItem(std::string str);
JsonValue* GetItem(const char* str);
int CountItem();
};
class JsonParser
{
public:
JsonParser();
~JsonParser();
JsonObject* Parse(std::string str);
private:
char QUOTATIONCHAR;
bool SkipEmpty(const char* data, long size, long* position);
std::string ParseString(const char* data, long size, long* position);
JsonObject* ParseJsonObject(const char* data, long size, long* position);
JsonBasicValue* ParseBool(const char* data, long size, long* position);
JsonBasicValue* ParseDouble(const char* data, long size, long* position);
JsonArray* ParseArray(const char* data, long size, long* position);
};
#endif