load_from_stream


Description:

[ Version ( since = "0.12" ) ]
public bool load_from_stream (InputStream stream, Cancellable? cancellable = null) throws Error

Loads the contents of an input stream and parses them.

If `cancellable` is not `NULL`, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, `G_IO_ERROR_CANCELLED` will be set on the given `error`.

Example: Parser example (Stream, sync):

public static int main (string[] args) {
if (args.length < 2) {
print ("Usage: test <filename.json>\n");
return -1;
}

// Load a file:
Json.Parser parser = new Json.Parser ();
try {
File file = File.new_for_commandline_arg (args[1]);
FileInputStream stream = file.read ();
parser.load_from_stream (stream);
} catch (Error e) {
print ("Unable to parse `%s': %s\n", args[1], e.message);
return -1;
}


// Get the root node:
Json.Node node = parser.get_root ();

// manipulate/read the object tree and then exit
// ...

node = null;
return 0;
}

valac --pkg json-glib-1.0 parser-example-stream-sync.vala

Parameters:

this

a parser

stream

the input stream with the JSON data

cancellable

a Cancellable

Returns:

`TRUE` if the data stream was successfully read and parsed, and `FALSE` otherwise