change code
Fork of MbedJSONValue_copy by
MbedJSONValue Class Reference
MbedJSONValue class. More...
#include <MbedJSONValue.h>
Public Types | |
enum | Type { TypeNull, TypeBoolean, TypeInt, TypeDouble, TypeString, TypeArray, TypeObject } |
All types which can be used. More... | |
Public Member Functions | |
MbedJSONValue () | |
MbedJSONValue constructor of type TypeNull. | |
MbedJSONValue (bool value) | |
MbedJSONValue constructor of type TypeBoolean. | |
MbedJSONValue (int value) | |
MbedJSONValue constructor of type TypeInt. | |
MbedJSONValue (double value) | |
MbedJSONValue constructor of type TypeDouble. | |
MbedJSONValue (std::string const &value) | |
MbedJSONValue constructor of type TypeString. | |
MbedJSONValue (const char *value) | |
MbedJSONValue constructor of type TypeString. | |
MbedJSONValue (MbedJSONValue const &rhs) | |
Copy constructor. | |
~MbedJSONValue () | |
Destructor. | |
MbedJSONValue & | operator= (MbedJSONValue const &rhs) |
= Operator overloading for an MbedJSONValue from an MbedJSONValue | |
MbedJSONValue & | operator= (int const &rhs) |
= Operator overloading for an MbedJSONValue from an int | |
MbedJSONValue & | operator= (bool const &rhs) |
= Operator overloading for an MbedJSONValue from a boolean | |
MbedJSONValue & | operator= (double const &rhs) |
= Operator overloading for an MbedJSONValue from a double | |
MbedJSONValue & | operator= (const char *rhs) |
= Operator overloading for an MbedJSONValue from a string | |
MbedJSONValue & | operator[] (int i) |
[] Operator overloading for an MbedJSONValue. | |
MbedJSONValue & | operator[] (std::string str) |
[] Operator overloading for an MbedJSONValue. | |
template<typename T > | |
const T & | get () const |
Retrieve the value of an MbedJSONValue object. | |
template<typename T > | |
T & | get () |
Retrieve the value of an MbedJSONValue object. | |
Type const & | getType () const |
Return the type of the MbedJSONValue object. | |
int | size () const |
Return the size of an MbedJSONValue object (works for TypeString, TypeArray or TypeObject) | |
bool | hasMember (char *name) |
Check for the existence in a TypeObject object of member identified by name. | |
std::string | serialize () |
Convert an MbedJSONValue in a JSON frame. |
Detailed Description
MbedJSONValue class.
Example:
- creation of an MbedJSONValue of type TypeObject containing two others MbedJSONValue: -one array of one string and one integer identified by "my_array" -a boolean identified by "my_boolean"
- serialization in JSON format of this object
#include "mbed.h" #include "MbedJSONValue.h" #include <string> int main() { MbedJSONValue demo; std::string s; //fill the object demo["my_array"][0] = "demo_string"; demo["my_array"][1] = 10; demo["my_boolean"] = false; //serialize it into a JSON string s = demo.serialize(); printf("json: %s\r\n", s.c_str()); }
Example:
- creation of an MbedJSONValue from a JSON string
- extraction of different values from this existing MbedJSONValue
#include "mbed.h" #include "MbedJSONValue.h" #include <string> int main() { MbedJSONValue demo; const char * json = "{\"my_array\": [\"demo_string\", 10], \"my_boolean\": true}"; //parse the previous string and fill the object demo parse(demo, json); std::string my_str; int my_int; bool my_bool; my_str = demo["my_array"][0].get<std::string>(); my_int = demo["my_array"][1].get<int>(); my_bool = demo["my_boolean"].get<bool>(); printf("my_str: %s\r\n", my_str.c_str()); printf("my_int: %d\r\n", my_int); printf("my_bool: %s\r\n", my_bool ? "true" : "false"); }
Definition at line 113 of file MbedJSONValue.h.
Member Enumeration Documentation
enum Type |
All types which can be used.
- Enumerator:
TypeNull Null type
TypeBoolean Boolean
TypeInt Integer
TypeDouble Double
TypeString String
TypeArray Array (contains MbedJSONValue)
TypeObject Object (contains MbedJSONValue identified by a name)
Definition at line 119 of file MbedJSONValue.h.
Constructor & Destructor Documentation
MbedJSONValue | ( | ) |
MbedJSONValue constructor of type TypeNull.
Definition at line 132 of file MbedJSONValue.h.
MbedJSONValue | ( | bool | value ) |
MbedJSONValue constructor of type TypeBoolean.
- Parameters:
-
value the object created will be initialized with this boolean
Definition at line 139 of file MbedJSONValue.h.
MbedJSONValue | ( | int | value ) |
MbedJSONValue constructor of type TypeInt.
- Parameters:
-
value the object created will be initialized with this integer
Definition at line 148 of file MbedJSONValue.h.
MbedJSONValue | ( | double | value ) |
MbedJSONValue constructor of type TypeDouble.
- Parameters:
-
value the object created will be initialized with this double
Definition at line 157 of file MbedJSONValue.h.
MbedJSONValue | ( | std::string const & | value ) |
MbedJSONValue constructor of type TypeString.
- Parameters:
-
value the object created will be initialized with this string
Definition at line 166 of file MbedJSONValue.h.
MbedJSONValue | ( | const char * | value ) |
MbedJSONValue constructor of type TypeString.
- Parameters:
-
value the object created will be initialized with this string
Definition at line 176 of file MbedJSONValue.h.
MbedJSONValue | ( | MbedJSONValue const & | rhs ) |
Copy constructor.
- Parameters:
-
rhs object which will be copied
Definition at line 185 of file MbedJSONValue.h.
~MbedJSONValue | ( | ) |
Destructor.
Definition at line 190 of file MbedJSONValue.h.
Member Function Documentation
T& get | ( | ) |
Retrieve the value of an MbedJSONValue object.
Let's suppose that we have an MbedJSONValue of type TypeInt. To retrieve this integer, you have to do: my_obj.get<int>();
- Returns:
- A reference on the value of the object
const T& get | ( | ) | const |
Retrieve the value of an MbedJSONValue object.
Let's suppose that we have an MbedJSONValue of type TypeString. To retrieve this string, you have to do: my_obj.get<std::string>();
- Returns:
- A contant reference on the value of the object
Type const& getType | ( | ) | const |
Return the type of the MbedJSONValue object.
- Returns:
- type of the MbedJSONValue object
Definition at line 282 of file MbedJSONValue.h.
bool hasMember | ( | char * | name ) |
Check for the existence in a TypeObject object of member identified by name.
- Parameters:
-
name Identifier
- Returns:
- true if the object is of type TypeObject AND contains a member named "name", false otherwise
Definition at line 37 of file MbedJSONValue.cpp.
MbedJSONValue & operator= | ( | MbedJSONValue const & | rhs ) |
= Operator overloading for an MbedJSONValue from an MbedJSONValue
- Parameters:
-
rhs object
- Returns:
- a reference on the MbedJSONValue affected
Definition at line 249 of file MbedJSONValue.cpp.
MbedJSONValue& operator= | ( | double const & | rhs ) |
= Operator overloading for an MbedJSONValue from a double
- Parameters:
-
rhs double
- Returns:
- a reference on the MbedJSONValue affected
Definition at line 222 of file MbedJSONValue.h.
MbedJSONValue& operator= | ( | int const & | rhs ) |
= Operator overloading for an MbedJSONValue from an int
- Parameters:
-
rhs integer
- Returns:
- a reference on the MbedJSONValue affected
Definition at line 206 of file MbedJSONValue.h.
MbedJSONValue& operator= | ( | const char * | rhs ) |
= Operator overloading for an MbedJSONValue from a string
- Parameters:
-
rhs string
- Returns:
- a reference on the MbedJSONValue affected
Definition at line 230 of file MbedJSONValue.h.
MbedJSONValue& operator= | ( | bool const & | rhs ) |
= Operator overloading for an MbedJSONValue from a boolean
- Parameters:
-
rhs boolean
- Returns:
- a reference on the MbedJSONValue affected
Definition at line 214 of file MbedJSONValue.h.
MbedJSONValue & operator[] | ( | int | i ) |
[] Operator overloading for an MbedJSONValue.
Each TypeObject object can contain an array of NB_TOKEN MbedJSONValue. This operator is useful to create an array or to retrieve an MbedJSONValue of an existing array.
- Parameters:
-
i index of the array
- Returns:
- a reference on the MbedJSONValue created or retrieved
Definition at line 166 of file MbedJSONValue.cpp.
MbedJSONValue & operator[] | ( | std::string | str ) |
[] Operator overloading for an MbedJSONValue.
Each TypeObject MbedJSONValue can contain NB_TOKEN MbedJSONValue IDENTIFIED BY A NAME This operator is useful to create a TypeObject MbedJSONValue or to retrieve an MbedJSONValue of an existing TypeObject.
- Parameters:
-
str identifier of the sub MbedJSONValue
- Returns:
- a reference on the MbedJSONValue created or retrieved
Definition at line 190 of file MbedJSONValue.cpp.
std::string serialize | ( | ) |
Convert an MbedJSONValue in a JSON frame.
- Returns:
- JSON string
Definition at line 78 of file MbedJSONValue.cpp.
int size | ( | ) | const |
Return the size of an MbedJSONValue object (works for TypeString, TypeArray or TypeObject)
- Returns:
- size
Definition at line 282 of file MbedJSONValue.cpp.
Generated on Thu Jul 14 2022 08:07:34 by 1.7.2