Generator


Object Hierarchy:

Json.Generator Json.Generator Json.Generator GLib.Object GLib.Object GLib.Object->Json.Generator

Description:

[ CCode ( type_id = "json_generator_get_type ()" ) ]
public class Generator : Object

`JsonGenerator` provides an object for generating a JSON data stream from a tree of [struct@Json.

Node] instances, and put it into a buffer or a file.

Example: Builder & Generators:

static int main (string[] args) {
// Build a object:
Json.Builder builder = new Json.Builder ();

builder.begin_object ();
builder.set_member_name ("url");
builder.add_string_value ("http://www.gnome.org/img/flash/two-thirty.png");

builder.set_member_name ("size");
builder.begin_array ();
builder.add_int_value (652);
builder.add_int_value (242);
builder.end_array ();

builder.end_object ();

// Generate a string:
// { "url" : "http://www.gnome.org/img/flash/two-thirty.png", "size" : [ 652, 242 ] }
Json.Generator generator = new Json.Generator ();
Json.Node root = builder.get_root ();
generator.set_root (root);

string str = generator.to_data (null);
print (str);
print ("\n");

return 0;
}

valac --pkg json-glib-1.0 builder-generator.vala


Namespace: Json
Package: json-glib-1.0

Content:

Properties:

Creation methods:

Methods:

Inherited Members: