Simpleson
|
The class used for manipulating JSON objects and arrays. More...
#include <json.h>
Classes | |
class | const_proxy |
Represents an entry as a constant proxy to the value. More... | |
class | const_value |
Represents an entry as a constant value. More... | |
class | entry |
Representation of a value in the object. More... | |
class | proxy |
A proxy that allows modification of the value. More... | |
Public Member Functions | |
jobject (bool array=false) | |
Default constructor. More... | |
jobject (const jobject &other) | |
Copy constructor. | |
virtual | ~jobject () |
Destructor. | |
bool | is_array () const |
Flag for differentiating objects and arrays. More... | |
size_t | size () const |
Returns the number of entries in the JSON object or array. | |
void | clear () |
Clears the JSON object or array. | |
bool | operator== (const json::jobject other) const |
Comparison operator. More... | |
bool | operator!= (const json::jobject other) const |
Comparison operator. | |
jobject & | operator= (const jobject rhs) |
Assignment operator. | |
jobject & | operator+= (const kvp &other) |
Appends a key-value pair to a JSON object. More... | |
jobject & | operator+= (const jobject &other) |
Appends one JSON object to another. | |
jobject | operator+ (jobject &other) |
Merges two JSON objects. | |
bool | has_key (const std::string &key) const |
Determines if an object contains a key. More... | |
void | set (const std::string &key, const std::string &value) |
Sets the value assocaited with the key. More... | |
std::string | get (const size_t index) const |
Returns the serialized value at a given index. More... | |
std::string | get (const std::string &key) const |
Returns the serialized value associated with a key. More... | |
void | remove (const std::string &key) |
Removes the entry associated with the key. More... | |
void | remove (const size_t index) |
Removes the entry at the specified index. More... | |
virtual jobject::proxy | operator[] (const std::string key) |
Returns an element of the JSON object. More... | |
virtual const jobject::const_proxy | operator[] (const std::string key) const |
Returns an element of the JSON object. More... | |
const jobject::const_value | array (const size_t index) const |
Returns the value of an element in an array. More... | |
operator std::string () const | |
std::string | as_string () const |
Serialzes the object or array. More... | |
std::string | pretty (unsigned int indent_level=0) const |
Returns a pretty (multi-line indented) serialzed representation of the object or array. More... | |
Static Public Member Functions | |
static jobject | parse (const char *input) |
Parses a serialized JSON string. More... | |
static jobject | parse (const std::string input) |
Parses a serialized JSON string. More... | |
static bool | tryparse (const char *input, jobject &output) |
The class used for manipulating JSON objects and arrays.
|
inline |
Default constructor.
array | If true, the instance is initialized as an array. If false, the instance is initalized as an object. |
|
inline |
Returns the value of an element in an array.
index | The index of the element to be returned |
|
inline |
Serialzes the object or array.
|
inline |
Returns the serialized value at a given index.
index | The index of the desired element |
|
inline |
Returns the serialized value associated with a key.
key | The key for the desired element |
json::invalid_key | Exception thrown if the key does not exist in the object or the object actually represents a JSON array |
|
inline |
Determines if an object contains a key.
key | The key to check for |
|
inline |
Flag for differentiating objects and arrays.
json::jobject::operator std::string | ( | ) | const |
Appends a key-value pair to a JSON object.
json::parsing_error | Thrown if the key-value is incompatable with the existing object (object/array mismatch) |
|
inline |
Comparison operator.
|
inlinevirtual |
Returns an element of the JSON object.
key | The key of the element to be returned |
json::invalid_key | Exception thrown if the object is actually a JSON array |
|
inlinevirtual |
Returns an element of the JSON object.
key | The key of the element to be returned |
json::invalid_key | Exception thrown if the object is actually a JSON array |
|
static |
Parses a serialized JSON string.
input | Serialized JSON string |
json::parsing_error | Thrown when the input string is not valid JSON |
|
inlinestatic |
Parses a serialized JSON string.
std::string json::jobject::pretty | ( | unsigned int | indent_level = 0 | ) | const |
Returns a pretty (multi-line indented) serialzed representation of the object or array.
indent_level | The number of indents (tabs) to start with |
|
inline |
Removes the entry at the specified index.
index | The index of the element to be removed |
void json::jobject::remove | ( | const std::string & | key | ) |
Removes the entry associated with the key.
key | The key of the key value pair to be removed |
void json::jobject::set | ( | const std::string & | key, |
const std::string & | value | ||
) |
Sets the value assocaited with the key.
If the key exists, then the value is updated. If the key does not exist, then the key value pair is added to the object.
key | The key for the entry |
value | The value for the entry |
json::invalid_key | Exception thrown if the object actually represents a JSON array |
|
inlinestatic |
/brief Attempts to parse the input string
input | A serialized JSON object or array | |
[out] | output | Should the parsing attempt be successful, the resultant JSON object or array |