gvariant_deserialize_data


Description:

[ Version ( since = "0.14" ) ]
public Variant? gvariant_deserialize_data (string json, ssize_t length, string? signature) throws Error

Converts a JSON string to a Variant value.

This method works exactly like gvariant_deserialize, but takes a JSON encoded string instead. The string is first converted to a Node using Parser, and then gvariant_deserialize is called.

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 json, or -1 if null-terminated

signature

A valid Variant type string, or null

Returns:

A newly created, floating Variant compliant with signature, or null on error


Namespace: Json
Package: json-glib-1.0