![]() |
![]() |
![]() |
JSON-GLib 0.6.2 Reference Manual | ![]() |
---|---|---|---|---|
enum JsonNodeType; #define JSON_NODE_TYPE (node) JsonNode; JsonNode* json_node_new (JsonNodeType type); JsonNode* json_node_copy (JsonNode *node); void json_node_free (JsonNode *node); void json_node_set_array (JsonNode *node, JsonArray *array); void json_node_take_array (JsonNode *node, JsonArray *array); JsonArray* json_node_get_array (JsonNode *node); JsonArray* json_node_dup_array (JsonNode *node); void json_node_set_object (JsonNode *node, JsonObject *object); void json_node_take_object (JsonNode *node, JsonObject *object); JsonObject* json_node_get_object (JsonNode *node); JsonObject* json_node_dup_object (JsonNode *node); void json_node_set_value (JsonNode *node, const GValue *value); void json_node_get_value (JsonNode *node, GValue *value); void json_node_set_boolean (JsonNode *node, gboolean value); gboolean json_node_get_boolean (JsonNode *node); void json_node_set_double (JsonNode *node, gdouble value); gdouble json_node_get_double (JsonNode *node); void json_node_set_int (JsonNode *node, gint value); gint json_node_get_int (JsonNode *node); void json_node_set_string (JsonNode *node, const gchar *value); const gchar* json_node_get_string (JsonNode *node); gchar* json_node_dup_string (JsonNode *node); JsonNode* json_node_get_parent (JsonNode *node); const gchar* json_node_type_name (JsonNode *node); GType json_node_get_value_type (JsonNode *node);
A JsonNode is a generic container of elements inside a JSON stream. It can contain fundamental types (integers, booleans, floating point numbers, strings) and complex types (arrays and objects).
When parsing a JSON data stream you extract the root node and walk
the node tree by retrieving the type of data contained inside the
node with the JSON_NODE_TYPE
macro. If the node contains a fundamental
type you can retrieve a copy of the GValue holding it with the
json_node_get_value()
function, and then use the GValue API to extract
the data; if the node contains a complex type you can retrieve the
JsonObject or the JsonArray using json_node_get_object()
or
json_node_get_array()
respectively, and then retrieve the nodes
they contain.
typedef enum { JSON_NODE_OBJECT, JSON_NODE_ARRAY, JSON_NODE_VALUE, JSON_NODE_NULL } JsonNodeType;
Indicates the content of a JsonNode.
The node contains a JsonObject | |
The node contains a JsonArray | |
The node contains a fundamental type | |
Special type, for nodes containing null |
#define JSON_NODE_TYPE(node) (((JsonNode *) (node))->type)
Evaluates to the JsonNodeType contained by node
|
a JsonNode |
typedef struct { } JsonNode;
A generic container of JSON data types. The contents of the JsonNode structure are private and should only be accessed via the provided functions and never directly.
JsonNodeType |
the type of node |
JsonNode* json_node_new (JsonNodeType type);
Creates a new JsonNode of type
.
|
a JsonNodeType |
Returns : |
the newly created JsonNode |
JsonNode* json_node_copy (JsonNode *node);
Copies node
. If the node contains complex data types then the reference
count of the objects is increased.
void json_node_free (JsonNode *node);
Frees the resources allocated by node
.
|
a JsonNode |
void json_node_set_array (JsonNode *node, JsonArray *array);
Sets array
inside node
and increases the JsonArray reference count
void json_node_take_array (JsonNode *node, JsonArray *array);
Sets array
into node
without increasing the JsonArray reference count.
JsonArray* json_node_get_array (JsonNode *node);
Retrieves the JsonArray stored inside a JsonNode
JsonArray* json_node_dup_array (JsonNode *node);
Retrieves the JsonArray stored inside a JsonNode and returns it with its reference count increased by one.
void json_node_set_object (JsonNode *node, JsonObject *object);
Sets objects
inside node
. The reference count of object
is increased.
|
a JsonNode |
|
a JsonObject |
void json_node_take_object (JsonNode *node, JsonObject *object);
Sets object
inside node
. The reference count of object
is not increased.
|
a JsonNode |
|
a JsonObject |
JsonObject* json_node_get_object (JsonNode *node);
Retrieves the JsonObject stored inside a JsonNode
|
a JsonNode |
Returns : |
the JsonObject |
JsonObject* json_node_dup_object (JsonNode *node);
Retrieves the JsonObject inside node
. The reference count of
the returned object is increased.
|
a JsonNode |
Returns : |
the JsonObject |
void json_node_set_value (JsonNode *node, const GValue *value);
Sets value
inside node
. The passed GValue is copied into the JsonNode
|
a JsonNode |
|
the GValue to set |
void json_node_get_value (JsonNode *node, GValue *value);
Retrieves a value from a JsonNode and copies into value
. When done
using it, call g_value_unset()
on the GValue.
|
a JsonNode |
|
return location for an uninitialized value |
void json_node_set_boolean (JsonNode *node, gboolean value);
Sets value
as the boolean content of the node
, replacing any existing
content.
|
a JsonNode of type JSON_NODE_VALUE
|
|
a boolean value |
gboolean json_node_get_boolean (JsonNode *node);
Gets the boolean value stored inside a JsonNode
|
a JsonNode of type JSON_NODE_VALUE
|
Returns : |
a boolean value. |
void json_node_set_double (JsonNode *node, gdouble value);
Sets value
as the double content of the node
, replacing any existing
content.
|
a JsonNode of type JSON_NODE_VALUE
|
|
a double value |
gdouble json_node_get_double (JsonNode *node);
Gets the double value stored inside a JsonNode
|
a JsonNode of type JSON_NODE_VALUE
|
Returns : |
a double value. |
void json_node_set_int (JsonNode *node, gint value);
Sets value
as the integer content of the node
, replacing any existing
content.
|
a JsonNode of type JSON_NODE_VALUE
|
|
an integer value |
gint json_node_get_int (JsonNode *node);
Gets the integer value stored inside a JsonNode
|
a JsonNode of type JSON_NODE_VALUE
|
Returns : |
an integer value. |
void json_node_set_string (JsonNode *node, const gchar *value);
Sets value
as the string content of the node
, replacing any existing
content.
|
a JsonNode of type JSON_NODE_VALUE
|
|
a string value |
const gchar* json_node_get_string (JsonNode *node);
Gets the string value stored inside a JsonNode
|
a JsonNode of type JSON_NODE_VALUE
|
Returns : |
a string value. |
gchar* json_node_dup_string (JsonNode *node);
Gets a copy of the string value stored inside a JsonNode
|
a JsonNode of type JSON_NODE_VALUE
|
Returns : |
a newly allocated string containing a copy of the JsonNode contents |
JsonNode* json_node_get_parent (JsonNode *node);
Retrieves the parent JsonNode of node
.
|
a JsonNode |
Returns : |
the parent node, or NULL if node is the root node
|
const gchar* json_node_type_name (JsonNode *node);
Retrieves the user readable name of the data type contained by node
.
|
a JsonNode |
Returns : |
a string containing the name of the type. The returned string is owned by the node and should never be modified or freed |