![]() |
![]() |
![]() |
JSON-GLib Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
JsonArray; JsonArray * json_array_new (void
); JsonArray * json_array_sized_new (guint n_elements
); JsonArray * json_array_ref (JsonArray *array
); void json_array_unref (JsonArray *array
); void json_array_add_element (JsonArray *array
,JsonNode *node
); JsonNode * json_array_get_element (JsonArray *array
,guint index_
); JsonNode * json_array_dup_element (JsonArray *array
,guint index_
); GList * json_array_get_elements (JsonArray *array
); guint json_array_get_length (JsonArray *array
); void json_array_remove_element (JsonArray *array
,guint index_
); void (*JsonArrayForeach) (JsonArray *array
,guint index_
,JsonNode *element_node
,gpointer user_data
); void json_array_foreach_element (JsonArray *array
,JsonArrayForeach func
,gpointer data
); void json_array_add_array_element (JsonArray *array
,JsonArray *value
); JsonArray * json_array_get_array_element (JsonArray *array
,guint index_
); void json_array_add_boolean_element (JsonArray *array
,gboolean value
); gboolean json_array_get_boolean_element (JsonArray *array
,guint index_
); void json_array_add_double_element (JsonArray *array
,gdouble value
); gdouble json_array_get_double_element (JsonArray *array
,guint index_
); void json_array_add_int_element (JsonArray *array
,gint64 value
); gint64 json_array_get_int_element (JsonArray *array
,guint index_
); void json_array_add_null_element (JsonArray *array
); gboolean json_array_get_null_element (JsonArray *array
,guint index_
); void json_array_add_object_element (JsonArray *array
,JsonObject *value
); JsonObject * json_array_get_object_element (JsonArray *array
,guint index_
); void json_array_add_string_element (JsonArray *array
,const gchar *value
); const gchar * json_array_get_string_element (JsonArray *array
,guint index_
);
JsonArray is the representation of the array type inside JSON. It contains JsonNodes, 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()
.
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
JsonArray * json_array_new (void
);
Creates a new JsonArray.
Returns : |
the newly created JsonArray |
JsonArray * json_array_sized_new (guint n_elements
);
Creates a new JsonArray with n_elements
slots already allocated.
|
number of slots to pre-allocate |
Returns : |
the newly created JsonArray |
JsonArray * json_array_ref (JsonArray *array
);
Increase by one the reference count of a JsonArray.
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.
|
a JsonArray |
void json_array_add_element (JsonArray *array
,JsonNode *node
);
Appends node
inside array
. The array will take ownership of the
JsonNode.
JsonNode * json_array_get_element (JsonArray *array
,guint index_
);
Retrieves the JsonNode containing the value of the element at index_
inside a JsonArray.
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
|
a JsonArray |
|
the index of the element to retrieve |
Returns : |
a copy of the JsonNode at the requested
index. Use json_node_free() when done. [transfer full]
|
Since 0.6
GList * json_array_get_elements (JsonArray *array
);
Gets the elements of a JsonArray as a list of JsonNodes.
|
a JsonArray |
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]
|
guint json_array_get_length (JsonArray *array
);
Retrieves the length of a JsonArray
|
a JsonArray |
Returns : |
the length of the array |
void json_array_remove_element (JsonArray *array
,guint index_
);
Removes the JsonNode inside array
at index_
freeing its allocated
resources.
|
a JsonArray |
|
the position of the element to be removed |
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
.
|
the iterated JsonArray |
|
the index of the element |
|
a JsonNode containing the value at index_
|
|
data passed to the function |
Since 0.8
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
.
|
a JsonArray |
|
the function to be called on each element. [scope call] |
|
data to be passed to the function. [closure] |
Since 0.8
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
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()
|
a JsonArray |
|
the index of the element to retrieve |
Returns : |
the array. [transfer none] |
Since 0.8
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()
|
a JsonArray |
|
a boolean value |
Since 0.8
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()
|
a JsonArray |
|
the index of the element to retrieve |
Returns : |
the integer value |
Since 0.8
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()
|
a JsonArray |
|
a floating point value |
Since 0.8
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()
|
a JsonArray |
|
the index of the element to retrieve |
Returns : |
the floating point value |
Since 0.8
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()
|
a JsonArray |
|
an integer value |
Since 0.8
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()
|
a JsonArray |
|
the index of the element to retrieve |
Returns : |
the integer value |
Since 0.8
void json_array_add_null_element (JsonArray *array
);
Conveniently adds a null element into array
See also: json_array_add_element()
, JSON_NODE_NULL
|
a JsonArray |
Since 0.8
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
|
a JsonArray |
|
the index of the element to retrieve |
Returns : |
TRUE if the element is null |
Since 0.8
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()
|
a JsonArray |
|
a JsonObject. [transfer full] |
Since 0.8
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()
|
a JsonArray |
|
the index of the element to retrieve |
Returns : |
the object. [transfer none] |
Since 0.8
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()
|
a JsonArray |
|
a string value |
Since 0.8
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()
|
a JsonArray |
|
the index of the element to retrieve |
Returns : |
the string value; the returned string is owned by the JsonArray and should not be modified or freed |
Since 0.8