![]() |
![]() |
![]() |
JSON-GLib 0.6.2 Reference Manual | ![]() |
---|---|---|---|---|
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_);
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.
|
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
|
guint json_array_get_length (JsonArray *array);
Retrieves the length of a JsonArray
|
a JsonArray |
Returns : |
the length of the array |