Class JSONData

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class JSONData

Summary
Public Methods
JSONData()
JSONData(xml)
JSONData(xmltext)
inline JSONData& getChild(key)
inline const JSONData& getChildConst(key) const
JSONData& addArrayValue(key, value)
JSONData& addArrayObject(key, object)
int getArraySize(key) const
string getArrayValue(key, index) const
JSONData& getArrayObject(key, index)
string toString() const
string& toString(result) const
bool fromString(text)
inline string toXML() const
Private Methods
string genQuotedString(text) const
string getQuotedValue(text, quotechar) const
string getNumber(text) const
string getKey(text)
bool getArrayValues(text)
bool getValue(key, text)
bool getKeyValuePairs(text)

#include <JSONData.h >

Super class: XMLData

Summary

This class represent hierarchical JSON data.

JSON properties are encapsulated in a HashArray class for any JSON node.

The data structure can be serialized using toString() and loaded from text using fromString().

Public Methods

JSONData()

Constructor. Create an empty hierarchical data structure.

Each level of hierarchy has a number of properties and child nodes.

JSONData(xml)

XMLData& xml

XML data to convert


Constructor. Covnert an hierarchical data structure from XML data.

Each level of hierarchy has a number of properties and child nodes.

JSONData(xmltext)

const string& xmltext

a serialized JSONData, HashArray or XMLData value


This constructor accepts serialized JSONData, HashArray, and XMLData text and converts into into this structure.

inline JSONData& getChild(key)

const string& key

the name of the sub-nodes to look for


Given a child node name, return the node of that child.  If more than one sub-node exists, return the first one.

Return value: child node; if not found, returns an empty node (valid() returns null false)

inline const JSONData& getChildConst(key) const

const string& key

the name of the sub-nodes to look for


Given a child node name, return the node of that child.  If more than one sub-node exists, return the first one.

Return value: child node (as a const); if not found, returns an empty node (valid() returns null false)

JSONData& addArrayValue(key, value)

const string& key

name of the array

const string& value

new value to add to the array


Add a value to an array. Note that you are responsible to make sure

all the values are of the same type (number, string, object).

Return value: the instance provided (not the array element)

JSONData& addArrayObject(key, object)

const string& key

name of the array

const JSONData& object

new object to add to the array


Add an object to an array. Note that you are responsible to make sure

all the objects are of the same.

Return value: the instance provided (not the array element)

int getArraySize(key) const

const string& key

name of the array


Return the number of elements in a named array.

Return value: the array size

string getArrayValue(key, index) const

const string& key

name of the array

int index

the array element number, e.g. 0+


Get an array value.

Return value: the instance provided (not the array element)

JSONData& getArrayObject(key, index)

const string& key

name of the array

int index

the array element number, e.g. 0+


Get an array object.

Return value: the instance provided (not the array element)

string toString() const

Convert the node and all sub-nodes into serialized text.

Return value: the JSONData, serialized as text

string& toString(result) const

string& result

(output) the serialized text


Convert the node and all sub-nodes into serialized text into the provided string.

Return value: the resulting output in the result parameter

bool fromString(text)

string text

XML as text to convert into our structure


Convert serialized JSONData text into the current JSONData structure, clearing any previous data.

Return value: true if data fully loaded

inline string toXML() const

Convert to text in XML.

Return value: text string in XML form representing the data

Private Methods

string genQuotedString(text) const

const string& text


Used by toString() to generate a quoted string (with escapes)

string getQuotedValue(text, quotechar) const

string& text

char quotechar


Parsing methods used by fromString()

string getNumber(text) const

string& text


string getKey(text)

string& text


bool getArrayValues(text)

string& text


bool getValue(key, text)

const string& key

string& text


bool getKeyValuePairs(text)

string& text