c# - How to convert a json string? -
can't seem working. have json string , want convert c# object:
{"name":"mousepos","args":[{"mousedet":{"rid":"1","posx":1277,"posy":275}}]}
i've been trying javascriptserializer i'm having no luck. i'm unsure how values of posx , posy. can suggest how this? help.
edit:
public class jsondata { public string name { get; set; } } public form1() { // ---- other stuff here ---- string json = data.messagetext; // json string. javascriptserializer ser = new javascriptserializer(); jsondata foo = ser.deserialize<jsondata>(json); messagebox.show(foo.name); // shows 'mousepos' }
you need extend out object model little bit cover it. based on you've got in example, like:
public class jsondata { public string name { get; set; } public arguments[] args { get; set; } } public class arguments { public mousedet mousedet { get; set; } } public class mousedet { public int rid { get; set; } public int posx { get; set; } public int posy { get; set; } } ... var posx = foo.args[0].mousedet.posx;
Comments
Post a Comment