Barracuda Application Server C/C++ Reference
NO
JVal Struct Reference

Detailed Description

JVal represents a value in a JSON tree.

An instance of the JParserValFact creates a syntax tree out of the parsed JSON data. An instance of JVal is one node in the tree. Method JParserValFact::getFirstVal returns the tree root element.

Most methods in this class take a JErr as argument. The methods set an error code if the JVal is not of the expected type or any other errors occur.

You can check for errors for each method called, but the methods are designed such that they abort the operation if the error flag in JErr is set. Some methods return NULL if an error is detected. You can check for NULL values, but all methods are designed such that they accept a NULL "this" pointer.

Examples:

See the JSON tutorial, section Using JParserValFact , for examples on how to use JVal.

#include <JVal.h>

Public Member Functions

JVType getType ()
 Returns the JSON type.
 
JValvget (JErr *err, const char **fmt, va_list *argList)
 Equivalent to get with variable argument list replaced by argList.
 
JValget (JErr *err, const char *fmt,...)
 Get any type of value(s) from a JVal node or JVal tree. More...
 
S32 getInt (JErr *e)
 Returns the integer value for an integer JVal type or attempts to convert the value to an integer. More...
 
void setInt (JErr *e, S32 v)
 Sets a new integer value or changes the JSON type and sets the integer value.
 
S64 getLong (JErr *e)
 Returns the integer as a long value for an integer JVal type or attempts to convert the value to a long integer. More...
 
void setLong (JErr *e, S64 v)
 Sets a new integer value or changes the JSON type and sets the integer value.
 
double getDouble (JErr *e)
 Returns the double value for a JVal float or attempts to convert the value to a float. More...
 
void setDouble (JErr *e, double v)
 Sets a new float value or changes the JSON type to float and sets the float value.
 
BaBool getBoolean (JErr *e)
 Returns the boolean value for a boolean JVal type or false if the JVal is JVType_Null. More...
 
void setBoolean (JErr *e, BaBool v)
 Sets a new boolean value or changes the JSON type and sets the boolean value.
 
void setNull (JErr *e)
 Changes the JSON type if not NULL.
 
const char * getString (JErr *e)
 Returns the string as a const or returns NULL if the JVAL is a NULL type. More...
 
void setString (JErr *e, char *v)
 Sets a string value and changes the JSON type if needed. More...
 
char * manageString (JErr *e)
 Similar to getString, but you must manage the value as the value is detached from the tree.
 
const char * getName ()
 Returns the member name if this value is part of a JSON object.
 
char * manageName ()
 Similar to getName, but you must manage the value as the value is detached from the tree.
 
JValgetNextElem ()
 Returns the next element if the parent is an object or an array.
 
JValgetObject (JErr *e)
 Returns the first child if an object. More...
 
JValgetArray (JErr *e)
 Returns the first child if an array. More...
 
JValgetJ (JErr *e)
 Returns the first child if an array or object. More...
 
JValmanageJ (JErr *e)
 Similar to getJ, but you must manage the JVal as the value is detached from the tree.
 
S32 getLength (JErr *e)
 Returns the elements left in the list. More...
 
bool isObjectMember ()
 Returns true if this is a child element in an object. More...
 
int unlink (JVal *child)
 Remove a child. More...
 
int addMember (JErr *e, const char *memberName, JVal *child, AllocatorIntf *dAlloc)
 Add a child to an object. More...
 
int add (JErr *e, JVal *child)
 Add a child to an array. More...
 
void terminate (AllocatorIntf *vAlloc, AllocatorIntf *dAlloc)
 Terminate the node and all sub nodes. More...