Re: [Vala] Help with json de/serialization



في ح، 04-09-2011 عند 20:22 -0700 ، كتب bsquared:
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?

the above should be Json.gobject_deserialize (typeof(CouchApp.Env), n)

HTH,
Abderrahim




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