json.net - Parsing JSON properties with spaces into objects -


i'm working third party system returns json.

i'm trying work out how deserialise following json;

{"getresponse": {     "results": {         "result 1": {"row": [{name:somename}]      } } 

i'm using newtonsoft json library. know how can parse .net objects?

to parse json objects using jsonconvert.deserializeobject<t> can make class structure this:

public class rootobject {     public getresponse getresponse { get; set; } }  public class getresponse {     public results results { get; set; } }  public class results {     [jsonproperty("result 1")]     public result1 result1 { get; set; } }  public class result1 {     [jsonproperty("row")]     public list<row> rows { get; set; } }  public class row {     public string name { get; set; } } 

then deserialize this:

string json = @" {     ""getresponse"": {         ""results"": {             ""result 1"": {                 ""row"": [                     {                         ""name"": ""somename""                     }                 ]             }         }     } }";  rootobject root = jsonconvert.deserializeobject<rootobject>(json); foreach (row row in root.getresponse.results.result1.rows) {     console.writeline(row.name); } 

Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -