asp.net - How do i deserialize facebook data -
i have retrieved data of facebook groups.
{ "groups": { "data": [ { "name": "name_1", "unread": 25, "bookmark_order": 13, "id": "000000000001" }, { "name": "name_2", "unread": 25, "bookmark_order": 999999999, "id": "00000000002" } ], "paging": { "next": "value_url" } }, "id": "123456" }
my attempt:
public class groups public property data() list(of facebookgroups) return m_data end set(value list(of facebookgroups)) m_data = value end set end property private m_data list(of facebookgroups) end class public class facebookgroups public property id() string return m_id end set(value string) m_id = value end set end property private m_id string public property name() string return m_name end set(value string) m_name = value end set end property private m_name string end class dim g = fbclient1.get("me?fields=groups") dim facebookgroups groups = new javascriptserializer().deserialize(of groups)(g) each item object in facebookgroups.data console.writeline("id: {0}, name: {1}", item.id, item.name) next
i getting errors. says not able convert string. correct way ? there other workaround deserializing objects ?
the output json string wrote above returns structure different class. class should along lines of:
class group, has properties data , id, data class should have list of class containing properties: name, unread, bookmark_order, id.
edit:
public class data public property name string public property unread integer public property bookmark_order integer public property id integer end class public class paging public property next string end class public class groups public property data list(of data) public property paging paging end class public class responseobject public property groups groups public property id integer end class
parsing responseobject should work, haven't tested myself.
edit 2: working example
the below code works me, reading data file c:\dev\tt.json, , groups parsed if step through.
sub main() dim g = my.computer.filesystem.readalltext("c:\dev\tt.json") dim facebookgroups responseobject = new javascriptserializer().deserialize(of responseobject)(g) end sub public class data public property name string public property unread integer public property bookmark_order integer public property id integer end class public class paging public property [next] string end class public class groups public property data list(of data) public property paging paging end class public class responseobject public property groups groups public property id integer end class
Comments
Post a Comment