Enums
Public Member Functions
-
JsonTree ()
Creates a null JsonTree .
-
JsonTree (const JsonTree &jsonTree)
Parses the JSON contained in the string xmlString .
-
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" ) );
-
JsonTree (const std::string &jsonString, ParseOptions parseOptions=ParseOptions())
Parses the JSON contained in the string jsonString .
-
JsonTree (const std::string &key, bool value)
Creates a JsonTree with key key and boolean value .
-
JsonTree (const std::string &key, double value)
Creates a JsonTree with key key and double value .
-
JsonTree (const std::string &key, float value)
Creates a JsonTree with key key and double value cast from float.
-
JsonTree (const std::string &key, int value)
Creates a JsonTree with key key and int value .
-
JsonTree (const std::string &key, const std::string &value)
Creates a JsonTree with key key and string value .
-
JsonTree (const std::string &key, const char *value)
Creates a JsonTree with key key and string value cast from const char*.
-
JsonTree (const std::string &key, uint32_t value)
Creates a JsonTree with key key and uint32_t value .
-
JsonTree (const std::string &key, int64_t value)
Creates a JsonTree with key key and int64_t value .
-
JsonTree (const std::string &key, uint64_t value)
Creates a JsonTree with key key and uint64_t value .
-
std::stringserialize () const
Returns the JsonTree as a string with standard formatting.
-
Iterbegin ()
Returns an Iter to the first child of this node.
-
ConstIterbegin () const
Returns a ConstIter to the first child of this node.
-
Iterend ()
Returns an Iter which marks the end of the children of this node.
-
ConstIterend () const
Returns a ConstIter which marks the end of the children of this node.
-
JsonTree &operator= (const JsonTree &jsonTree)
Assigns the JsonTree a new value, and creates it if it doesn't exist.
-
JsonTree &operator[] (const std::string &relativePath)
! Returns the child at relativePath . Throws ExcChildNotFound if none matches.
JsonTree node = myNode[ "path.to.child" ];
-
const JsonTree &operator[] (const std::string &relativePath) const
! Returns the child at relativePath . Throws ExcChildNotFound if none matches.
JsonTree node = myNode[ "path.to.child" ];
-
JsonTree &operator[] (size_t index)
Returns the child at index . Throws ExcChildNotFound if none matches.
-
const JsonTree &operator[] (size_t index) const
Returns the child at index . Throws ExcChildNotFound if none matches.
-
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 &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 &getChild (size_t index)
Returns the child at index . Throws ExcChildNotFound if none matches.
-
const JsonTree &getChild (size_t index) const
Returns the child at index . Throws ExcChildNotFound if none matches.
-
const Container &getChildren () const
Returns a reference to the node's list of children nodes.
-
size_tgetNumChildren () const
Returns the number of child nodes.
-
boolhasChild (const std::string &relativePath, bool caseSensitive=false, char separator= '.') const
! Returns whether the child at relativePath exists.
bool nodeExists = myNode.hasChild( "path.to.child" );
-
boolhasChildren () const
Returns whether this node has a parent node.
-
JsonTree &getParent ()
Returns a reference to the node which is the parent of this node.
-
const JsonTree &getParent () const
Returns a reference to the node which is the parent of this node.
-
boolhasParent () const
Returns whether this node has a parent node.
-
voidclear ()
Removes all child nodes.
-
JsonTree &addChild (const JsonTree &newChild)
! 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.
-
voidpushBack (const JsonTree &newChild)
! 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.
-
voidremoveChild (size_t index)
Removes the child at index . Throws ExcChildNotFound if none matches.
-
IterremoveChild (Iter pos)
Removes the child at pos . Throws ExcChildNotFound if none matches.
-
voidreplaceChild (size_t index, const JsonTree &newChild)
Replaces the child at index with JsonTree newChild . Throws ExcChildNotFound if none matches.
-
voidreplaceChild (Iter pos, const JsonTree &newChild)
Replaces the child at pos with JsonTree newChild . Throws ExcChildNotFound if none matches.
-
voidwrite (const fs::path &path, 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.
-
voidwrite (DataTargetRef target, 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 std::string &getKey () const
Returns the node's key as a string. Returns index if node does not have a key.
-
std::stringgetPath (char separator= '.') const
! Returns a path to this node, separated by the character separator .
-
TgetValue () const
Returns the value of the node cast to T using ci::fromString() .
float value = myNode.getValue<float>();
!
-
TgetValueForKey (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:
getChild( relativePath ).getValue<T>()
-
TgetValueAtIndex (size_t index) const
Returns the value of the child at relativePath . Default type T is std::string. Convenience shortcut for:
getChild( index ).getValue<T>()
-
const std::string &getValue () const
Returns the value of the node as a string.
-
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:
getChild( relativePath ).getValue<T>()
-
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:
getChild( index ).getValue<T>()
-
getNodeType () const
Returns the type of the node.
Static Public Member Functions
Friends
-
friend CI_API std::ostream &operator<< (std::ostream &out, const JsonTree &json)
Streams the JsonTree json to std::ostream out with standard formatting.