ESPectro32 Library
Library for using ESPectro32 board
 All Classes Functions Variables Enumerations Enumerator Pages
JSON.h
1 /*
2  * JSON.h
3  *
4  * Created on: May 23, 2017
5  * Author: kolban
6  */
7 
8 #ifndef COMPONENTS_CPP_UTILS_JSON_H_
9 #define COMPONENTS_CPP_UTILS_JSON_H_
10 #include <cJSON.h>
11 #include <string>
12 
13 // Forward declarations
14 class JsonObject;
15 class JsonArray;
16 
20 class JSON {
21 public:
22  static JsonObject createObject();
23  static JsonArray createArray();
24  static void deleteObject(JsonObject jsonObject);
25  static void deleteArray(JsonArray jsonArray);
26  static JsonObject parseObject(std::string text);
27  static JsonArray parseArray(std::string text);
28 }; // JSON
29 
30 
34 class JsonArray {
35 public:
36  JsonArray(cJSON *node);
37  int getInt(int item);
38  JsonObject getObject(int item);
39  std::string getString(int item);
40  bool getBoolean(int item);
41  double getDouble(int item);
42  void addBoolean(bool value);
43  void addDouble(double value);
44  void addInt(int value);
45  void addObject(JsonObject value);
46  void addString(std::string value);
47  std::string toString();
48  std::size_t size();
52  cJSON *m_node;
53 }; // JsonArray
54 
55 
59 class JsonObject {
60 public:
61  JsonObject(cJSON *node);
62  int getInt(std::string name);
63  JsonObject getObject(std::string name);
64  std::string getString(std::string name);
65  bool getBoolean(std::string name);
66  double getDouble(std::string name);
67  void setArray(std::string name, JsonArray array);
68  void setBoolean(std::string name, bool value);
69  void setDouble(std::string name, double value);
70  void setInt(std::string name, int value);
71  void setObject(std::string name, JsonObject value);
72  void setString(std::string name, std::string value);
73  std::string toString();
77  cJSON *m_node;
78 }; // JsonObject
79 
80 
81 #endif /* COMPONENTS_CPP_UTILS_JSON_H_ */
void setDouble(std::string name, double value)
Set the named double property.
Definition: JSON.cpp:289
double getDouble(std::string name)
Get the named double value from the object.
Definition: JSON.cpp:222
A JSON object.
Definition: JSON.h:59
std::string getString(std::string name)
Get the named string value from the object.
Definition: JSON.cpp:255
void setString(std::string name, std::string value)
Set the named string property.
Definition: JSON.cpp:322
double getDouble(int item)
Get the indexed double value from the array.
Definition: JSON.cpp:139
Top level JSON handler.
Definition: JSON.h:20
void setInt(std::string name, int value)
Set the named int property.
Definition: JSON.cpp:300
int getInt(std::string name)
Get the named int value from the object.
Definition: JSON.cpp:233
static void deleteArray(JsonArray jsonArray)
Delete a JSON array.
Definition: JSON.cpp:36
void addObject(JsonObject value)
Add an object value to the array.
Definition: JSON.cpp:106
bool getBoolean(int item)
Get the indexed boolean value from the array.
Definition: JSON.cpp:125
static JsonArray parseArray(std::string text)
Parse a string that contains a JSON array.
Definition: JSON.cpp:55
void setArray(std::string name, JsonArray array)
Set the named array property.
Definition: JSON.cpp:267
JsonObject getObject(std::string name)
Get the named object value from the object.
Definition: JSON.cpp:244
cJSON * m_node
The underlying cJSON node.
Definition: JSON.h:52
static JsonObject parseObject(std::string text)
Parse a string that contains a JSON object.
Definition: JSON.cpp:65
void addDouble(double value)
Add a double value to the array.
Definition: JSON.cpp:88
std::string toString()
Convert the JSON object to a string.
Definition: JSON.cpp:331
int getInt(int item)
Get the indexed int value from the array.
Definition: JSON.cpp:150
std::size_t size()
Get the number of elements from the array.
Definition: JSON.cpp:194
JsonObject getObject(int item)
Get the indexed object value from the array.
Definition: JSON.cpp:161
void addString(std::string value)
Add a string value to the array.
Definition: JSON.cpp:115
static void deleteObject(JsonObject jsonObject)
Delete a JSON object.
Definition: JSON.cpp:45
static JsonObject createObject()
Create an empty JSON object.
Definition: JSON.cpp:26
void addInt(int value)
Add an int value to the array.
Definition: JSON.cpp:97
void addBoolean(bool value)
Add a boolean value to the array.
Definition: JSON.cpp:79
void setObject(std::string name, JsonObject value)
Set the named object property.
Definition: JSON.cpp:311
void setBoolean(std::string name, bool value)
Set the named boolean property.
Definition: JSON.cpp:278
std::string getString(int item)
Get the indexed object value from the array.
Definition: JSON.cpp:172
bool getBoolean(std::string name)
Get the named boolean value from the object.
Definition: JSON.cpp:208
cJSON * m_node
The underlying cJSON node.
Definition: JSON.h:77
std::string toString()
Convert the JSON array to a string.
Definition: JSON.cpp:182
A JSON array.
Definition: JSON.h:34
static JsonArray createArray()
Create an empty JSON array.
Definition: JSON.cpp:17