summaryrefslogtreecommitdiff
path: root/contrib/json-test.vala
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@openedhand.com>2008-01-29 19:13:15 +0000
committerEmmanuele Bassi <ebassi@openedhand.com>2008-01-29 19:13:15 +0000
commit3a9ec8f1ca9bf525875c3fbfaf1ab2f3c708bf36 (patch)
tree801edb382bad000e3cd91bb4798da5e58bc65f89 /contrib/json-test.vala
parente8a59f086f43e5abd5414033ea8c9a886eb112ed (diff)
downloadjson-glib-work.tar.gz
Update the JSON-GLib Vala bindingswork
Add a dependencies file, so that valac can simply use the json-glib-1.0 package and correcly chain up all the dependencies needed (at the moment, only glib-2.0). Update the vapi file to match with the GLib bindings with regards to the out length parameters and some weak pointers. The only way to properly solve the weak assignments issue would be to make JsonNode, JsonObject and JsonArray proper GObjects, or at least add reference counting to JsonNode. Not going to happend in 0.6, but it's worth adding it to the 1.0 roadmap.
Diffstat (limited to 'contrib/json-test.vala')
-rw-r--r--contrib/json-test.vala62
1 files changed, 30 insertions, 32 deletions
diff --git a/contrib/json-test.vala b/contrib/json-test.vala
index 9091694..f5ec3b5 100644
--- a/contrib/json-test.vala
+++ b/contrib/json-test.vala
@@ -12,58 +12,56 @@ using GLib;
using Json;
public class Sample : GLib.Object {
- public void dump_node (Json.Node node)
- {
- switch (node.type ())
- {
+ private void dump_node (Json.Node node) {
+ switch (node.type ()) {
case Json.NodeType.OBJECT:
- var obj = node.get_object ();
+ Json.Object obj = node.get_object ();
stdout.printf ("* size: %d\n", obj.get_size ());
- foreach (weak string member in obj.get_members ())
- {
- var val = obj.dup_member (member);
+ foreach (weak string member in obj.get_members ()) {
+ weak Json.Node val = obj.get_member (member);
- stdout.printf ("* member[\"%s\"] type: %s, value:\n",
- member,
- val.type_name ());
+ stdout.printf ("* member[\"%s\"] type: %s, value:\n",
+ member,
+ val.type_name ());
- dump_node (val);
- }
+ dump_node (val);
+ }
break;
case Json.NodeType.ARRAY:
- var array = node.get_array ();
+ Json.Array array = node.get_array ();
stdout.printf ("* length: %d\n", array.get_length ());
- var count = 0;
- foreach (weak Json.Node element in array.get_elements ())
- {
- stdout.printf ("* element[%d] type: %s, value:\n",
- count++,
- element.type_name ());
+ int count = 0;
+ foreach (weak Json.Node element in array.get_elements ()) {
+ stdout.printf ("* element[%d] type: %s, value:\n",
+ count++,
+ element.type_name ());
- dump_node (element);
- }
+ dump_node (element);
+ }
break;
case Json.NodeType.VALUE:
- switch (node.get_value_type ())
- {
+ switch (node.get_value_type ()) {
case typeof (int):
- stdout.printf ("*** %d\n", node.get_int ());
+ stdout.printf ("*** value '%d'\n", node.get_int ());
break;
case typeof (double):
- stdout.printf ("*** %f\n", node.get_double ());
+ stdout.printf ("*** value '%f'\n", node.get_double ());
break;
case typeof (string):
- stdout.printf ("*** %s\n", node.get_string ());
+ stdout.printf ("*** value '%s'\n", node.get_string ());
break;
- }
+ case typeof (bool):
+ stdout.printf ("*** value '%s'\n", node.get_boolean () ? "true" : "false");
+ break;
+ }
break;
case Json.NodeType.NULL:
- stdout.printf ("*** null\n");
+ stdout.printf ("*** value: 'nul'l\n");
break;
}
}
@@ -91,7 +89,7 @@ public class Sample : GLib.Object {
gen.root = node;
var len = 0;
- var dump = gen.to_data (ref len);
+ var dump = gen.to_data (out len);
stdout.printf ("** object dump (length: %d): %s\n",
len, dump);
};
@@ -100,13 +98,13 @@ public class Sample : GLib.Object {
stdout.printf ("parsing complete\n");
};
- try { parser.load_from_data (buffer); }
+ try { parser.load_from_data (buffer, -1); }
catch (Json.ParserError e) {
stdout.printf ("%s\n", e.message);
return;
}
- var root = parser.get_root ();
+ weak Json.Node root = parser.get_root ();
stdout.printf ("root node type: %s\n", root.type_name ());
dump_node (root);