[Vala] Help with json de/serialization



Hello,

I am trying to move some JSON to GLib.Object descendant but cannot
seem to figure it out.

The JSON is the .couchapprc file which looks like this:
{
 "env" : {
   "default" : {
     "db" : "http://localhost:5984/mydb";
   },
   "prod" : {
     "db" : "http://admin:password myhost com/mydb"
   }
 }
}

The first problem I had was in defining the target object.  It looks
like a Map<string, Object>.

I defined an object and collection:
class CouchApp.Env : Glib.Object {
 string db;
}
Map<string, CouchApp.Env> env_map = new map<string, CouchApp.Env> ();

Then I get the "env" member Object:
Json.Object o = p.get_root ().get_object ().get_member  ("env").get_object ();

loop through the env members with:
o.foreach_member((o,s,n) => { [...] });

But I get an error [1] when I call this in the loop:
Json.gobject_deserialize (CouchApp.Env, n)

* So, what am I doing wrong here?

Ideally I would like to be able to use [2] and pass the contents of
the couchapprc file, but I read that the json de/serializer may not be
able to handle collections/arrays:

* Can I this be done? How?

Thanks.
--
Regards,
-Brian

[1] - ]$ make
 GEN    .vala-aux/couchdb_sample.vapi
 VALAC  couchdb_sample.vala
src/couchdb_sample.vala:83.49-83.60: error: Invalid type for argument 1
CouchApp.Env env = Json.gobject_deserialize (CouchApp.Env, n);
                                            ^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

[2] - Json.public static Object construct_gobject (Type gtype, string
data, size_t length)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]