![]() |
Cinder
0.9.1
|
#include <Json.h>
Classes | |
class | ExcChildNotFound |
class | Exception |
class | ExcJsonParserError |
class | ExcNonConvertible |
class | ParseOptions |
class | WriteOptions |
Public Types | |
enum | NodeType { NODE_UNKNOWN, NODE_NULL, NODE_ARRAY, NODE_OBJECT, NODE_VALUE } |
Public Member Functions | |
JsonTree () | |
JsonTree (const JsonTree &jsonTree) | |
JsonTree (DataSourceRef dataSource, ParseOptions parseOptions=ParseOptions()) | |
JsonTree (const std::string &jsonString, ParseOptions parseOptions=ParseOptions()) | |
JsonTree (const std::string &key, bool value) | |
JsonTree (const std::string &key, double value) | |
JsonTree (const std::string &key, float value) | |
JsonTree (const std::string &key, int value) | |
JsonTree (const std::string &key, const std::string &value) | |
JsonTree (const std::string &key, const char *value) | |
JsonTree (const std::string &key, uint32_t value) | |
JsonTree (const std::string &key, int64_t value) | |
JsonTree (const std::string &key, uint64_t value) | |
std::string | serialize () const |
Iter | begin () |
ConstIter | begin () const |
Iter | end () |
ConstIter | end () const |
JsonTree & | operator= (const JsonTree &jsonTree) |
JsonTree & | operator[] (const std::string &relativePath) |
const JsonTree & | operator[] (const std::string &relativePath) const |
JsonTree & | operator[] (size_t index) |
const JsonTree & | operator[] (size_t index) const |
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) |
const JsonTree & | getChild (size_t index) const |
const Container & | getChildren () const |
size_t | getNumChildren () const |
bool | hasChild (const std::string &relativePath, bool caseSensitive=false, char separator= '.') const |
bool | hasChildren () const |
JsonTree & | getParent () |
const JsonTree & | getParent () const |
bool | hasParent () const |
void | clear () |
JsonTree & | addChild (const JsonTree &newChild) |
void | pushBack (const JsonTree &newChild) |
void | removeChild (size_t index) |
Iter | removeChild (Iter pos) |
void | replaceChild (size_t index, const JsonTree &newChild) |
void | replaceChild (Iter pos, const JsonTree &newChild) |
void | write (const fs::path &path, WriteOptions writeOptions=WriteOptions()) |
void | write (DataTargetRef target, WriteOptions writeOptions=WriteOptions()) |
const std::string & | getKey () const |
std::string | getPath (char separator= '.') const |
template<typename T > | |
T | getValue () const |
template<typename T > | |
T | getValueForKey (const std::string &relativePath, bool caseSensitive=false, char separator= '.') const |
template<typename T > | |
T | getValueAtIndex (size_t index) const |
const std::string & | getValue () const |
const std::string & | getValueForKey (const std::string &relativePath, bool caseSensitive=false, char separator= '.') const |
const std::string & | getValueAtIndex (size_t index) const |
NodeType | getNodeType () const |
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) |
|
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.
void cinder::JsonTree::pushBack | ( | 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.
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.
void cinder::JsonTree::replaceChild | ( | size_t | index, |
const JsonTree & | newChild | ||
) |
Replaces the child at index with JsonTree newChild. Throws ExcChildNotFound if none matches.
void cinder::JsonTree::replaceChild | ( | Iter | pos, |
const JsonTree & | newChild | ||
) |
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>();
!
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.