Method

JsonReaderread_element

since: 0.12

Declaration [src]

gboolean
json_reader_read_element (
  JsonReader* reader,
  guint index_
)

Description [src]

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 json_reader_get_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:

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

After reading the value, you should call json_reader_end_element() to reposition the cursor inside the reader, e.g.:

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 json_reader_end_element() is called. This means that, if used conditionally, json_reader_end_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.

Available since: 0.12

Parameters

index_

Type: guint

The index of the element.

Return value

Type: gboolean

TRUE on success, and FALSE otherwise.