Parser
Object Hierarchy:
Description:
[
CCode ( type_id =
"json_parser_get_type ()" ) ]
public class Parser :
Object
`JsonParser` provides an object for parsing a JSON data stream, either inside a file or inside a static buffer.
Using `JsonParser`
The `JsonParser` API is fairly simple:
```c gboolean parse_json (const char *filename) { g_autoptr(JsonParser) parser = json_parser_new (); g_autoptr(GError) error = NULL
json_parser_load_from_file (parser, filename, &error); if (error != NULL) { g_critical ("Unable to parse '
s': s", filename, error->message); return FALSE; }
g_autoptr(JsonNode) root = json_parser_get_root (parser);
// manipulate the object tree from the root node
return TRUE } ```
By default, the entire process of loading the data and parsing it is synchronous; the [method@Json.Parser.load_from_stream_async] API
will load the data asynchronously, but parse it in the main context as the signals of the parser must be emitted in the same thread. If
you do not use signals, and you wish to also parse the JSON data without blocking, you should use a `GTask` and the synchronous
`JsonParser` API inside the task itself.
Content:
Properties:
Creation methods:
Methods:
Signals:
- public virtual signal void array_element (Array array, int index_)
The `array_element` signal is emitted each
time a parser has successfully parsed a single element of a JSON array.
- public virtual signal void array_end (Array array)
The `array_end` signal is emitted each
time a parser has successfully parsed an entire JSON array.
- public virtual signal void array_start ()
The `array_start` signal is emitted each
time a parser starts parsing a JSON array.
- public virtual signal void error (void* error)
The `error` signal is emitted each time a
parser encounters an error in a JSON stream.
- public virtual signal void object_end (Object object)
The `object_end` signal is emitted each
time a parser has successfully parsed an entire JSON object.
- public virtual signal void object_member (Object object, string member_name)
The `object_member` signal is emitted each
time a parser has successfully parsed a single member of a JSON object.
- public virtual signal void object_start ()
This signal is emitted each time a parser starts parsing a JSON
object.
- public virtual signal void parse_end ()
This signal is emitted when a parser successfully finished parsing a
JSON data stream.
- public virtual signal void parse_start ()
This signal is emitted when a parser starts parsing a JSON data
stream.
Inherited Members:
All known members inherited from class GLib.Object