Top |
JsonNode * | json_gvariant_serialize () |
gchar * | json_gvariant_serialize_data () |
GVariant * | json_gvariant_deserialize () |
GVariant * | json_gvariant_deserialize_data () |
Use json_gvariant_serialize()
and json_gvariant_serialize_data()
to
convert from any GVariant value to a JsonNode tree or its string
representation.
Use json_gvariant_deserialize()
and json_gvariant_deserialize_data()
to
obtain the GVariant value from a JsonNode tree or directly from a JSON
string.
Since many GVariant data types cannot be directly represented as JSON, a GVariant type string (signature) should be provided to these methods in order to obtain a correct, type-contrained result. If no signature is provided, conversion can still be done, but the resulting GVariant value will be "guessed" from the JSON data types using the following rules:
JsonNode *
json_gvariant_serialize (GVariant *variant
);
Converts variant
to a JSON tree.
A JsonNode representing the root of the
JSON data structure obtained from variant
.
[transfer full]
Since: 0.14
gchar * json_gvariant_serialize_data (GVariant *variant
,gsize *length
);
Converts variant
to its JSON encoded string representation. This method
is actually a helper function. It uses json_gvariant_serialize()
to obtain the
JSON tree, and then JsonGenerator to stringify it.
variant |
A GVariant to convert |
|
length |
Return location for the length of the returned
string, or |
[out][allow-none] |
Since: 0.14
GVariant * json_gvariant_deserialize (JsonNode *json_node
,const gchar *signature
,GError **error
);
Converts a JSON data structure to a GVariant value using signature
to
resolve ambiguous data types. If no error occurs, the resulting GVariant
is guaranteed to conform to signature
.
If signature
is not NULL
but does not represent a valid GVariant type
string, NULL
is returned and error is set to G_IO_ERROR_INVALID_ARGUMENT
.
If a signature
is provided but the JSON structure cannot be mapped to it,
NULL
is returned and error is set to G_IO_ERROR_INVALID_DATA
.
If signature
is NULL
, the conversion is done based strictly on the types
in the JSON nodes.
The returned variant has a floating reference that will need to be sunk by the caller code.
json_node |
A JsonNode to convert |
|
signature |
A valid GVariant type string, or |
[allow-none] |
error |
A pointer to a GError |
A newly created, floating GVariant
compliant with signature
, or NULL
on error.
[transfer none]
Since: 0.14
GVariant * json_gvariant_deserialize_data (const gchar *json
,gssize length
,const gchar *signature
,GError **error
);
Converts a JSON string to a GVariant value. This method works exactly
like json_gvariant_deserialize()
, but takes a JSON encoded string instead.
The string is first converted to a JsonNode using JsonParser, and then
json_gvariant_deserialize()
is called.
The returned variant has a floating reference that will need to be sunk by the caller code.
json |
A JSON data string |
|
length |
The length of |
|
signature |
A valid GVariant type string, or |
[allow-none] |
error |
A pointer to a GError |
A newly created, floating GVariant compliant
with signature
, or NULL
on error.
[transfer none]
Since: 0.14