vb.net 2010 - Deserialize JSON keep getting null referance exception -
okay, want deserialize json https://openrct.net/ajax/chat.php. problem no matter try, end null reference exception when try access stored data. have been trying close hour, googling , trying different things, , @ loss how this. please me out.
imports newtonsoft imports newtonsoft.json imports newtonsoft.json.linq imports system.net public class form1 dim ws new webclient '/ajax/chat.php 'and /ajax/chat.php?latest=55 chat messages after id private sub form1_load(sender object, e eventargs) handles mybase.load end sub public class postwrapper public posts() post end class public class post public property a() string public property m() string public property t() string end class private sub button1_click(sender object, e eventargs) handles button1.click dim json string = ws.downloadstring("https://openrct.net/ajax/chat.php") msgbox(json) dim postwrapper = jsonconvert.deserializeobject(of postwrapper)(json) ' deserialize array of post objects msgbox(postwrapper.posts(0).m) 'errors here. end sub end class
thank you.
your object classes deserializing wrong, can use jsonutils.com generating classes json string or url.
here classes json,
public class m public property id string public property string public property m string public property t string end class public class example public property m m() public property l string end class dim postwrapper = jsonconvert.deserializeobject(of example)(json) msgbox(postwrapper.m)
Comments
Post a Comment