read_element


Description:

public bool read_element (uint index_)

Advances the cursor of the reader to the element of the array or the member of the object at the given position.

You can use [[email protected]_value] and its wrapper functions to retrieve the value of the element; for instance, the following code will read the first element of the array at the current cursor position:

```c json_reader_read_element (reader, 0); int_value = json_reader_get_int_value (reader); ```

After reading the value, you should call [[email protected]_element] to reposition the cursor inside the reader, e.g.:

```c const char *str_value = NULL;

json_reader_read_element (reader, 1); str_value = json_reader_get_string_value (reader); json_reader_end_element (reader);

json_reader_read_element (reader, 2); str_value = json_reader_get_string_value (reader); json_reader_end_element (reader); ```

If the reader is not currently on an array or an object, or if the index is bigger than the size of the array or the object, the reader will be put in an error state until [[email protected]_element] is called. This means that, if used conditionally, [ [email protected]_element] must be called on all branches:

```c if (!json_reader_read_element (reader, 1)) { g_propagate_error (error, json_reader_get_error (reader)); json_reader_end_element ( reader); return FALSE; } else { const char *str_value = json_reader_get_string_value (reader); json_reader_end_element (reader);

// use str_value

return TRUE; } ```c

Parameters:

this

a reader

index_

the index of the element

Returns:

`TRUE` on success, and `FALSE` otherwise




2022 vala-language.org