#include <Json.h>
Classes | |
class | ExcChildNotFound |
Exception expressing the absence of an expected child node. More... | |
class | Exception |
Base class for JsonTree exceptions. More... | |
class | ExcJsonParserError |
Exception expressing the existence of errors when serializing or deserializing JSON. More... | |
class | ExcNonConvertible |
Exception expressing the inability to convert a node's value to a requested type. More... | |
class | ParseOptions |
Options for JSON parsing. Passed to the JsonTree constructor. More... | |
class | WriteOptions |
Options for JSON writing. Passed to the write method. More... | |
Public Types | |
enum | NodeType { NODE_UNKNOWN, NODE_NULL, NODE_ARRAY, NODE_OBJECT, NODE_VALUE } |
Enum listing all types of JSON nodes understood by the parser. More... | |
Public Member Functions | |
JsonTree () | |
Creates a null JsonTree. More... | |
JsonTree (const JsonTree &jsonTree) | |
Parses the JSON contained in the string xmlString. More... | |
JsonTree (DataSourceRef dataSource, ParseOptions parseOptions=ParseOptions()) | |
Parses JSON contained in dataSource. Commonly used with the results of loadUrl(), loadFile() or loadResource(). JsonTree myDoc( loadUrl( "http://search.twitter.com/search.json?q=libcinder&rpp=10&result_type=recent" ) ); More... | |
JsonTree (const std::string &jsonString, ParseOptions parseOptions=ParseOptions()) | |
Parses the JSON contained in the string jsonString . More... | |
JsonTree (const std::string &key, bool value) | |
Creates a JsonTree with key key and boolean value . More... | |
JsonTree (const std::string &key, double value) | |
Creates a JsonTree with key key and double value . More... | |
JsonTree (const std::string &key, float value) | |
Creates a JsonTree with key key and double value cast from float. More... | |
JsonTree (const std::string &key, int value) | |
Creates a JsonTree with key key and int value . More... | |
JsonTree (const std::string &key, const std::string &value) | |
Creates a JsonTree with key key and string value . More... | |
JsonTree (const std::string &key, const char *value) | |
Creates a JsonTree with key key and string value cast from const char*. More... | |
JsonTree (const std::string &key, uint32_t value) | |
Creates a JsonTree with key key and uint32_t value . More... | |
JsonTree (const std::string &key, int64_t value) | |
Creates a JsonTree with key key and int64_t value . More... | |
JsonTree (const std::string &key, uint64_t value) | |
Creates a JsonTree with key key and uint64_t value . More... | |
std::string | serialize () const |
Returns the JsonTree as a string with standard formatting. More... | |
Iter | begin () |
Returns an Iter to the first child of this node. More... | |
ConstIter | begin () const |
Returns a ConstIter to the first child of this node. More... | |
Iter | end () |
Returns an Iter which marks the end of the children of this node. More... | |
ConstIter | end () const |
Returns a ConstIter which marks the end of the children of this node. More... | |
JsonTree & | operator= (const JsonTree &jsonTree) |
Assigns the JsonTree a new value, and creates it if it doesn't exist. More... | |
JsonTree & | operator[] (const std::string &relativePath) |
const JsonTree & | operator[] (const std::string &relativePath) const |
JsonTree & | operator[] (size_t index) |
Returns the child at index. Throws ExcChildNotFound if none matches. More... | |
const JsonTree & | operator[] (size_t index) const |
Returns the child at index. Throws ExcChildNotFound if none matches. More... | |
JsonTree & | getChild (const std::string &relativePath, bool caseSensitive=false, char separator= '.') |
const JsonTree & | getChild (const std::string &relativePath, bool caseSensitive=false, char separator= '.') const |
JsonTree & | getChild (size_t index) |
Returns the child at index. Throws ExcChildNotFound if none matches. More... | |
const JsonTree & | getChild (size_t index) const |
Returns the child at index. Throws ExcChildNotFound if none matches. More... | |
const Container & | getChildren () const |
Returns a reference to the node's list of children nodes. More... | |
size_t | getNumChildren () const |
Returns the number of child nodes. More... | |
bool | hasChild (const std::string &relativePath, bool caseSensitive=false, char separator= '.') const |
bool | hasChildren () const |
Returns whether this node has a parent node. More... | |
JsonTree & | getParent () |
Returns a reference to the node which is the parent of this node. More... | |
const JsonTree & | getParent () const |
Returns a reference to the node which is the parent of this node. More... | |
bool | hasParent () const |
Returns whether this node has a parent node. More... | |
void | clear () |
Removes all child nodes. More... | |
JsonTree & | addChild (const JsonTree &newChild) |
void | pushBack (const JsonTree &newChild) |
void | removeChild (size_t index) |
Removes the child at index. Throws ExcChildNotFound if none matches. More... | |
Iter | removeChild (Iter pos) |
Removes the child at pos. Throws ExcChildNotFound if none matches. More... | |
void | replaceChild (size_t index, const JsonTree &newChild) |
Replaces the child at index with JsonTree newChild. Throws ExcChildNotFound if none matches. More... | |
void | replaceChild (Iter pos, const JsonTree &newChild) |
Replaces the child at pos with JsonTree newChild. Throws ExcChildNotFound if none matches. More... | |
void | write (const fs::path &path, WriteOptions writeOptions=WriteOptions()) |
void | write (DataTargetRef target, WriteOptions writeOptions=WriteOptions()) |
const std::string & | getKey () const |
Returns the node's key as a string. Returns index if node does not have a key. More... | |
std::string | getPath (char separator= '.') const |
template<typename T > | |
T | getValue () const |
Returns the value of the node cast to T using ci::fromString(). float value = myNode.getValue<float>( "key" ); More... | |
template<typename T > | |
T | getValueForKey (const std::string &relativePath, bool caseSensitive=false, char separator= '.') const |
Returns the value of the child at relativePath. Default type T is std::string. Convenience shortcut for: More... | |
template<typename T > | |
T | getValueAtIndex (size_t index) const |
Returns the value of the child at relativePath. Default type T is std::string. Convenience shortcut for: More... | |
const std::string & | getValue () const |
Returns the value of the node as a string. More... | |
const std::string & | getValueForKey (const std::string &relativePath, bool caseSensitive=false, char separator= '.') const |
Returns the value of the child at relativePath. Default type T is std::string. Convenience shortcut for: More... | |
const std::string & | getValueAtIndex (size_t index) const |
Returns the value of the child at relativePath. Default type T is std::string. Convenience shortcut for: More... | |
NodeType | getNodeType () const |
Returns the type of the node. More... | |
Static Public Member Functions | |
static JsonTree | makeArray (const std::string &key="") |
static JsonTree | makeObject (const std::string &key="") |
Friends | |
std::ostream & | operator<< (std::ostream &out, const JsonTree &json) |
Streams the JsonTree json to std::ostream out with standard formatting. More... | |
|
explicit |
Creates a null JsonTree.
cinder::JsonTree::JsonTree | ( | const JsonTree & | jsonTree | ) |
Parses the JSON contained in the string xmlString.
|
explicit |
Parses JSON contained in dataSource. Commonly used with the results of loadUrl(), loadFile() or loadResource().
JsonTree myDoc( loadUrl( "http://search.twitter.com/search.json?q=libcinder&rpp=10&result_type=recent" ) );
|
explicit |
Parses the JSON contained in the string jsonString .
|
explicit |
Creates a JsonTree with key key and boolean value .
|
explicit |
Creates a JsonTree with key key and double value .
|
explicit |
Creates a JsonTree with key key and double value cast from float.
|
explicit |
Creates a JsonTree with key key and int value .
|
explicit |
Creates a JsonTree with key key and string value .
|
explicit |
Creates a JsonTree with key key and string value cast from const char*.
|
explicit |
Creates a JsonTree with key key and uint32_t value .
|
explicit |
Creates a JsonTree with key key and int64_t value .
|
explicit |
Creates a JsonTree with key key and uint64_t value .
|
static |
! Creates a JsonTree with key key and an empty array.
|
static |
! Creates a JsonTree with key key as an empty object.
string cinder::JsonTree::serialize | ( | ) | const |
Returns the JsonTree as a string with standard formatting.
JsonTree::Iter cinder::JsonTree::begin | ( | ) |
Returns an Iter to the first child of this node.
JsonTree::ConstIter cinder::JsonTree::begin | ( | ) | const |
Returns a ConstIter to the first child of this node.
JsonTree::Iter cinder::JsonTree::end | ( | ) |
Returns an Iter which marks the end of the children of this node.
JsonTree::ConstIter cinder::JsonTree::end | ( | ) | const |
Returns a ConstIter which marks the end of the children of this node.
Assigns the JsonTree a new value, and creates it if it doesn't exist.
JsonTree & cinder::JsonTree::operator[] | ( | const std::string & | relativePath | ) |
! Returns the child at relativePath. Throws ExcChildNotFound if none matches.
JsonTree node = myNode[ "path.to.child" ];
const JsonTree & cinder::JsonTree::operator[] | ( | const std::string & | relativePath | ) | const |
! Returns the child at relativePath. Throws ExcChildNotFound if none matches.
JsonTree node = myNode[ "path.to.child" ];
JsonTree & cinder::JsonTree::operator[] | ( | size_t | index | ) |
Returns the child at index. Throws ExcChildNotFound if none matches.
const JsonTree & cinder::JsonTree::operator[] | ( | size_t | index | ) | const |
Returns the child at index. Throws ExcChildNotFound if none matches.
JsonTree & cinder::JsonTree::getChild | ( | const std::string & | relativePath, |
bool | caseSensitive = false , |
||
char | separator = '.' |
||
) |
! Returns the child at relativePath. Throws ExcChildNotFound if none matches.
JsonTree node = myNode.getChild( "path.to.child" );
const JsonTree & cinder::JsonTree::getChild | ( | const std::string & | relativePath, |
bool | caseSensitive = false , |
||
char | separator = '.' |
||
) | const |
! Returns the child at relativePath. Throws ExcChildNotFound if none matches.
JsonTree node = myNode.getChild( "path.to.child" );
JsonTree & cinder::JsonTree::getChild | ( | size_t | index | ) |
Returns the child at index. Throws ExcChildNotFound if none matches.
const JsonTree & cinder::JsonTree::getChild | ( | size_t | index | ) | const |
Returns the child at index. Throws ExcChildNotFound if none matches.
const JsonTree::Container & cinder::JsonTree::getChildren | ( | ) | const |
Returns a reference to the node's list of children nodes.
size_t cinder::JsonTree::getNumChildren | ( | ) | const |
Returns the number of child nodes.
bool cinder::JsonTree::hasChild | ( | const std::string & | relativePath, |
bool | caseSensitive = false , |
||
char | separator = '.' |
||
) | const |
! Returns whether the child at relativePath exists.
bool nodeExists = myNode.hasChild( "path.to.child" );
bool cinder::JsonTree::hasChildren | ( | ) | const |
Returns whether this node has a parent node.
JsonTree & cinder::JsonTree::getParent | ( | ) |
Returns a reference to the node which is the parent of this node.
const JsonTree & cinder::JsonTree::getParent | ( | ) | const |
Returns a reference to the node which is the parent of this node.
bool cinder::JsonTree::hasParent | ( | ) | const |
Returns whether this node has a parent node.
void cinder::JsonTree::clear | ( | ) |
Removes all child nodes.
! Appends a copy of the node newChild to the children of this node. If this is a value node, it will change to an object or an array. If newChild has a key, this becomes an object node. If not, this becomes an array node. Returns reference to itself.
! Appends a copy of the node newChild to the children of this node. If this is a value node, it will change to an object or an array. If newChild has a key, this becomes an object node. If not, this becomes an array node.
void cinder::JsonTree::removeChild | ( | size_t | index | ) |
Removes the child at index. Throws ExcChildNotFound if none matches.
Iter cinder::JsonTree::removeChild | ( | Iter | pos | ) |
Removes the child at pos. Throws ExcChildNotFound if none matches.
Replaces the child at index with JsonTree newChild. Throws ExcChildNotFound if none matches.
Replaces the child at pos with JsonTree newChild. Throws ExcChildNotFound if none matches.
void cinder::JsonTree::write | ( | const fs::path & | path, |
JsonTree::WriteOptions | writeOptions = WriteOptions() |
||
) |
! Writes this JsonTree to path with standard formatting. If writeOptions creates a document then an implicit parent object node is created when necessary and this is treated as the root element. If writeOptions indents then the JSON string will be indented.
void cinder::JsonTree::write | ( | DataTargetRef | target, |
JsonTree::WriteOptions | writeOptions = WriteOptions() |
||
) |
! Writes this JsonTree to target. If writeOptions creates a document then an implicit parent object node is created when necessary and this is treated as the root element. If writeOptions indents then the JSON string will be indented.
const string & cinder::JsonTree::getKey | ( | ) | const |
Returns the node's key as a string. Returns index if node does not have a key.
string cinder::JsonTree::getPath | ( | char | separator = '.' | ) | const |
! Returns a path to this node, separated by the character separator.
T cinder::JsonTree::getValue | ( | ) | const |
Returns the value of the node cast to T using ci::fromString().
float value = myNode.getValue<float>( "key" );
!
T cinder::JsonTree::getValueForKey | ( | const std::string & | relativePath, |
bool | caseSensitive = false , |
||
char | separator = '.' |
||
) | const |
T cinder::JsonTree::getValueAtIndex | ( | size_t | index | ) | const |
const std::string& cinder::JsonTree::getValue | ( | ) | const |
Returns the value of the node as a string.
const std::string& cinder::JsonTree::getValueForKey | ( | const std::string & | relativePath, |
bool | caseSensitive = false , |
||
char | separator = '.' |
||
) | const |
const std::string& cinder::JsonTree::getValueAtIndex | ( | size_t | index | ) | const |
NodeType cinder::JsonTree::getNodeType | ( | ) | const |
Returns the type of the node.
|
friend |
Streams the JsonTree json to std::ostream out with standard formatting.