gvariant_deserialize_data
Description:
[ CCode ( returns_floating_reference = true ) ]
[ Version ( since = "0.14" ) ]
public Variant? gvariant_deserialize_data (string json, ssize_t length, string? signature) throws Error
[ Version ( since = "0.14" ) ]
public Variant? gvariant_deserialize_data (string json, ssize_t length, string? signature) throws Error
Converts a JSON string to a `GVariant` value.
This function works exactly like [func@Json.gvariant_deserialize], but takes a JSON encoded string instead.
The string is first converted to a [struct@Json.Node] using [class@Json.Parser], and then `json_gvariant_deserialize` is called on the node.
The returned variant has a floating reference that will need to be sunk by the caller code.
Example: GVariant deserialization (string):
public static int main (string[] args) {
try {
string data = """{ "a" : 3, "b" : 4 }""";
// Deserialization:
Variant variant = Json.gvariant_deserialize_data (data, -1, null);
print (variant.print (true));
print ("\n");
} catch (Error e) {
assert_not_reached ();
}
return 0;
}
valac --pkg json-glib-1.0 deserialization-variant-data.vala
Parameters:
json |
A JSON data string |
length |
The length of |
signature |
A valid `GVariant` type string |
Returns:
A newly created `GVariant`D compliant |
Namespace: Json
Package: json-glib-1.0