Class
JsonParser
Description [src]
class Json.Parser : GObject.Object
{
/* No available fields */
}
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:
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 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.
Constructors
json_parser_new_immutable
Creates a new parser instance with its JsonParser:immutable
property set to TRUE
to create immutable output trees.
since: 1.2
Instance methods
json_parser_get_current_pos
Retrieves the current position inside the current line, starting from 0.
json_parser_has_assignment
A JSON data stream might sometimes contain an assignment, like:.
since: 0.4
json_parser_load_from_mapped_file
Loads a JSON stream from the content of filename
and parses it.
since: 1.6
json_parser_load_from_stream_finish
Finishes an asynchronous stream loading started with
json_parser_load_from_stream_async()
.
since: 0.12
Properties
Json.Parser:immutable
Whether the tree built by the parser should be immutable when created.
since: 1.2
Json.Parser:strict
Whether the parser should be strictly conforming to the JSON format, or allow custom extensions like comments.
since: 1.10
Signals
Json.Parser::array-element
The ::array-element
signal is emitted each time a parser
has successfully parsed a single element of a JSON array.
deprecated: 1.10
Json.Parser::array-end
The ::array-end
signal is emitted each time a parser
has successfully parsed an entire JSON array.
deprecated: 1.10
Json.Parser::array-start
The ::array-start
signal is emitted each time a parser
starts parsing a JSON array.
deprecated: 1.10
Json.Parser::error
The ::error
signal is emitted each time a parser encounters
an error in a JSON stream.
deprecated: 1.10
Json.Parser::object-end
The ::object-end
signal is emitted each time a parser
has successfully parsed an entire JSON object.
deprecated: 1.10
Json.Parser::object-member
The ::object-member
signal is emitted each time a parser
has successfully parsed a single member of a JSON object.
deprecated: 1.10
Json.Parser::object-start
This signal is emitted each time a parser starts parsing a JSON object.
deprecated: 1.10
Json.Parser::parse-end
This signal is emitted when a parser successfully finished parsing a JSON data stream.
deprecated: 1.10
Json.Parser::parse-start
This signal is emitted when a parser starts parsing a JSON data stream.
deprecated: 1.10
Signals inherited from GObject (1)
GObject::notify
The notify signal is emitted on an object when one of its properties has its value set through g_object_set_property(), g_object_set(), et al.
Class structure
struct JsonParserClass {
void (* parse_start) (
JsonParser* parser
);
void (* object_start) (
JsonParser* parser
);
void (* object_member) (
JsonParser* parser,
JsonObject* object,
const gchar* member_name
);
void (* object_end) (
JsonParser* parser,
JsonObject* object
);
void (* array_start) (
JsonParser* parser
);
void (* array_element) (
JsonParser* parser,
JsonArray* array,
gint index_
);
void (* array_end) (
JsonParser* parser,
JsonArray* array
);
void (* parse_end) (
JsonParser* parser
);
void (* error) (
JsonParser* parser,
const GError* error
);
void (* _json_reserved1) (
void
);
void (* _json_reserved2) (
void
);
void (* _json_reserved3) (
void
);
void (* _json_reserved4) (
void
);
void (* _json_reserved5) (
void
);
void (* _json_reserved6) (
void
);
void (* _json_reserved7) (
void
);
void (* _json_reserved8) (
void
);
}
The class structure for the JsonParser type.
Class members
parse_start: void (* parse_start) ( JsonParser* parser )
Class handler for the JsonParser::parse-start signal.
object_start: void (* object_start) ( JsonParser* parser )
Class handler for the JsonParser::object-start signal.
object_member: void (* object_member) ( JsonParser* parser, JsonObject* object, const gchar* member_name )
Class handler for the JsonParser::object-member signal.
object_end: void (* object_end) ( JsonParser* parser, JsonObject* object )
Class handler for the JsonParser::object-end signal.
array_start: void (* array_start) ( JsonParser* parser )
Class handler for the JsonParser::array-start signal.
array_element: void (* array_element) ( JsonParser* parser, JsonArray* array, gint index_ )
Class handler for the JsonParser::array-element signal.
array_end: void (* array_end) ( JsonParser* parser, JsonArray* array )
Class handler for the JsonParser::array-end signal.
parse_end: void (* parse_end) ( JsonParser* parser )
Class handler for the JsonParser::parse-end signal.
error: void (* error) ( JsonParser* parser, const GError* error )
Class handler for the JsonParser::error signal.
_json_reserved1: void (* _json_reserved1) ( void )
No description available.
_json_reserved2: void (* _json_reserved2) ( void )
No description available.
_json_reserved3: void (* _json_reserved3) ( void )
No description available.
_json_reserved4: void (* _json_reserved4) ( void )
No description available.
_json_reserved5: void (* _json_reserved5) ( void )
No description available.
_json_reserved6: void (* _json_reserved6) ( void )
No description available.
_json_reserved7: void (* _json_reserved7) ( void )
No description available.
_json_reserved8: void (* _json_reserved8) ( void )
No description available.