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
Post a Comment