In case of error, json.reader.Reader will be set in an error state; all subsequent
calls will simply be ignored until a function that resets the error state is
called, e.g.:
// ask for the 7th element; if the element does not exist, the// reader will be put in an error state
json_reader_read_element (reader, 6);
// in case of error, this will return NULL, otherwise it will// return the value of the element
str = json_reader_get_string_value (value);
// this function resets the error state if any was set
json_reader_end_element (reader);
// like the example above, but in this case we print out the// error immediatelyif (!json_reader_read_element (reader, 6))
{
const GError *error = json_reader_get_error (reader);
g_print ("Unable to read the element: %s", error->message);
}
json.reader.Reader provides a simple, cursor-based API for parsing a JSON DOM.
It is similar, in spirit, to the XML Reader API.
Using json.reader.Reader
Error handling
In case of error, json.reader.Reader will be set in an error state; all subsequent calls will simply be ignored until a function that resets the error state is called, e.g.:
If you want to detect the error state as soon as possible, you can use json.reader.Reader.getError: