Top |
Functions
Description
JsonArray is the representation of the array type inside JSON. It contains JsonNode elements, which may contain fundamental types, other arrays or objects.
Since arrays can be expensive, they are reference counted. You can control
the lifetime of a JsonArray using json_array_ref()
and json_array_unref()
.
To append an element, use json_array_add_element()
.
To extract an element at a given index, use json_array_get_element()
.
To retrieve the entire array in list form, use json_array_get_elements()
.
To retrieve the length of the array, use json_array_get_length()
.
Functions
json_array_sized_new ()
JsonArray *
json_array_sized_new (guint n_elements
);
Creates a new JsonArray with n_elements
slots already allocated.
[constructor]
json_array_ref ()
JsonArray *
json_array_ref (JsonArray *array
);
Increase by one the reference count of a JsonArray.
json_array_unref ()
void
json_array_unref (JsonArray *array
);
Decreases by one the reference count of a JsonArray. If the reference count reaches zero, the array is destroyed and all its allocated resources are freed.
json_array_seal ()
void
json_array_seal (JsonArray *array
);
Seals the JsonArray, making it immutable to further changes. This will recursively seal all elements in the array too.
If the array
is already immutable, this is a no-op.
Since: 1.2
json_array_is_immutable ()
gboolean
json_array_is_immutable (JsonArray *array
);
Check whether the given array
has been marked as immutable by calling
json_array_seal()
on it.
Since: 1.2
json_array_hash ()
guint
json_array_hash (gconstpointer key
);
Calculate a hash value for the given key
(a JsonArray).
The hash is calculated over the array and all its elements, recursively. If the array is immutable, this is a fast operation; otherwise, it scales proportionally with the length of the array.
Since: 1.2
json_array_equal ()
gboolean json_array_equal (gconstpointer a
,gconstpointer b
);
Check whether a
and b
are equal JsonArrays, meaning they have the same
number of elements, and the values of elements in corresponding positions
are equal.
Since: 1.2
json_array_add_element ()
void json_array_add_element (JsonArray *array
,JsonNode *node
);
Appends node
inside array
. The array will take ownership of the
JsonNode.
json_array_get_element ()
JsonNode * json_array_get_element (JsonArray *array
,guint index_
);
Retrieves the JsonNode containing the value of the element at index_
inside a JsonArray.
json_array_dup_element ()
JsonNode * json_array_dup_element (JsonArray *array
,guint index_
);
Retrieves a copy of the JsonNode containing the value of the
element at index_
inside a JsonArray
Returns
a copy of the JsonNode at the requested
index. Use json_node_unref()
when done.
[transfer full]
Since: 0.6
json_array_get_elements ()
GList *
json_array_get_elements (JsonArray *array
);
Gets the elements of a JsonArray as a list of JsonNode instances.
Returns
a GList
containing the elements of the array. The contents of the list are
owned by the array and should never be modified or freed. Use
g_list_free()
on the returned list when done using it.
[element-type JsonNode][transfer container]
json_array_get_length ()
guint
json_array_get_length (JsonArray *array
);
Retrieves the length of a JsonArray
json_array_remove_element ()
void json_array_remove_element (JsonArray *array
,guint index_
);
Removes the JsonNode inside array
at index_
freeing its allocated
resources.
JsonArrayForeach ()
void (*JsonArrayForeach) (JsonArray *array
,guint index_
,JsonNode *element_node
,gpointer user_data
);
The function to be passed to json_array_foreach_element()
. You
should not add or remove elements to and from array
within
this function. It is safe to change the value of element_node
.
Since: 0.8
json_array_foreach_element ()
void json_array_foreach_element (JsonArray *array
,JsonArrayForeach func
,gpointer data
);
Iterates over all elements of array
and calls func
on
each one of them.
It is safe to change the value of a JsonNode of the array
from within the iterator func
, but it is not safe to add or
remove elements from the array
.
Parameters
array |
||
func |
the function to be called on each element. |
[scope call] |
data |
data to be passed to the function. |
[closure] |
Since: 0.8
json_array_add_array_element ()
void json_array_add_array_element (JsonArray *array
,JsonArray *value
);
Conveniently adds an array into array
. The array
takes ownership
of the newly added JsonArray
See also: json_array_add_element()
, json_node_take_array()
Since: 0.8
json_array_get_array_element ()
JsonArray * json_array_get_array_element (JsonArray *array
,guint index_
);
Conveniently retrieves the array from the element at index_
inside array
See also: json_array_get_element()
, json_node_get_array()
Since: 0.8
json_array_add_boolean_element ()
void json_array_add_boolean_element (JsonArray *array
,gboolean value
);
Conveniently adds a boolean value
into array
See also: json_array_add_element()
, json_node_set_boolean()
Since: 0.8
json_array_get_boolean_element ()
gboolean json_array_get_boolean_element (JsonArray *array
,guint index_
);
Conveniently retrieves the boolean value of the element at index_
inside array
See also: json_array_get_element()
, json_node_get_boolean()
Since: 0.8
json_array_add_double_element ()
void json_array_add_double_element (JsonArray *array
,gdouble value
);
Conveniently adds a floating point value
into array
See also: json_array_add_element()
, json_node_set_double()
Since: 0.8
json_array_get_double_element ()
gdouble json_array_get_double_element (JsonArray *array
,guint index_
);
Conveniently retrieves the floating point value of the element at
index_
inside array
See also: json_array_get_element()
, json_node_get_double()
Since: 0.8
json_array_add_int_element ()
void json_array_add_int_element (JsonArray *array
,gint64 value
);
Conveniently adds an integer value
into array
See also: json_array_add_element()
, json_node_set_int()
Since: 0.8
json_array_get_int_element ()
gint64 json_array_get_int_element (JsonArray *array
,guint index_
);
Conveniently retrieves the integer value of the element at index_
inside array
See also: json_array_get_element()
, json_node_get_int()
Since: 0.8
json_array_add_null_element ()
void
json_array_add_null_element (JsonArray *array
);
Conveniently adds a null element into array
See also: json_array_add_element()
, JSON_NODE_NULL
Since: 0.8
json_array_get_null_element ()
gboolean json_array_get_null_element (JsonArray *array
,guint index_
);
Conveniently retrieves whether the element at index_
is set to null
See also: json_array_get_element()
, JSON_NODE_TYPE()
, JSON_NODE_NULL
Since: 0.8
json_array_add_object_element ()
void json_array_add_object_element (JsonArray *array
,JsonObject *value
);
Conveniently adds an object into array
. The array
takes ownership
of the newly added JsonObject
See also: json_array_add_element()
, json_node_take_object()
Since: 0.8
json_array_get_object_element ()
JsonObject * json_array_get_object_element (JsonArray *array
,guint index_
);
Conveniently retrieves the object from the element at index_
inside array
See also: json_array_get_element()
, json_node_get_object()
Since: 0.8
json_array_add_string_element ()
void json_array_add_string_element (JsonArray *array
,const gchar *value
);
Conveniently adds a string value
into array
See also: json_array_add_element()
, json_node_set_string()
Since: 0.8
json_array_get_string_element ()
const gchar * json_array_get_string_element (JsonArray *array
,guint index_
);
Conveniently retrieves the string value of the element at index_
inside array
See also: json_array_get_element()
, json_node_get_string()
Returns
the string value; the returned string is owned by the JsonArray and should not be modified or freed
Since: 0.8
Types and Values
JsonArray
typedef struct _JsonArray JsonArray;
A JSON array type. The contents of the JsonArray structure are private and should only be accessed by the provided API