javascript - JSON parsing using .NET deserialize() with nested "list" -


edit: simplified classes

{   "name": "final five",   "bio": null,   "noplayers": "0",   "roster": {     "players0": {       "playerid": "3516",       "name": "gate",       "role": "mid lane",       "isstarter": 1     },     "players1": {       "playerid": "3826",       "name": "veritas",       "role": "ad carry",       "isstarter": 1     },     "players2": {       "playerid": "4054",       "name": "novel",       "role": "support",       "isstarter": 1     },     "players3": {       "playerid": "4142",       "name": "wizardry",       "role": "top lane",       "isstarter": 0     },     "players4": {       "playerid": "4555",       "name": "metroid",       "role": "jungler",       "isstarter": 0     },     "players5": {       "playerid": "4554",       "name": "chau",       "role": "jungler",       "isstarter": 0     },     "players6": {       "playerid": "3847",       "name": "biofrost",       "role": "support",       "isstarter": 0     }   },   "logourl": "http://riot-web-cdn.s3-us-west-1.amazonaws.com/lolesports/s3fs-public/final-five-logo.png",   "profileurl": "http://na.lolesports.com/node/3498",   "teamphotourl": "http://na.lolesports.com/",   "acronym": "f5" } 

i have json being received on end. problem i'm having trying parse players list instead of individual elements since number of players may vary. i've tried using arrays , lists. these classes have set up

public class player     {         public string playerid { get; set; }         public string name { get; set; }         public string role { get; set; }         public int isstarter { get; set; }     }      public class roster     {         public player players0 { get; set; }         public player players1 { get; set; }         public player players2 { get; set; }         public player players3 { get; set; }         public player players4 { get; set; }         public player players5 { get; set; }         public player players6 { get; set; }     }      public class team     {         public string name { get; set; }         public object bio { get; set; }         public string noplayers { get; set; }         public roster roster { get; set; }         public string logourl { get; set; }         public string profileurl { get; set; }         public string teamphotourl { get; set; }         public string acronym { get; set; }     } 

this deserialization:

 team team = new javascriptserializer().deserialize<team>(responsetext); 

one possibility deserialize dynamic object , convert strongly-typed object. so:

var dict = new javascriptserializer().deserialize<dynamic>(responsetext); 

the resulting dict object dictionary, each property represented name-value pair in dictionary. nested objects, such roster , contained playersx objects represented dictionaries.

so, example, name property of player1 object so:

assert.areequal("veritas", dict["roster"]["players1"]["name"]); 

if helps @ all, make roster property dynamic, so:

public class team {     public string name { get; set; }     public object bio { get; set; }     public string noplayers { get; set; }     public dynamic roster { get; set; }     public string logourl { get; set; }     public string profileurl { get; set; }     public string teamphotourl { get; set; }     public string acronym { get; set; } } 

then property deserialized dictionary of dictionaries.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -