Tuesday, 15 April 2014

c# - Null exception on nested JSON object -



c# - Null exception on nested JSON object -

i'm using newtonsoft deserialize array of json objects. i'm able deserialize entire object exception of nested @attributes objects.

here snippet of item i'm trying parse:

"item" : [{ "title" : "bloody.birthday.1981.1080p.bluray.x264-7sins", "guid" : "https:\/\/api.nzb.su\/details\/35e799ce66c3290db629b68e3bac20f9", "link" : "https://", "comments" : "https://url", "pubdate" : "wed, 25 jun 2014 12:47:16 -0400", "category" : "movies > hd", "description" : "bloody.birthday.1981.1080p.bluray.x264-7sins", "enclosure" : { "@attributes" : { "url" : "https://url", "length" : "6777211483", "type" : "application\/x-nzb" } }, "attr" : [{ "@attributes" : { "name" : "category", "value" : "2000" } }, { "@attributes" : { "name" : "category", "value" : "2040" } }, { "@attributes" : { "name" : "size", "value" : "6777211483" } } ] } ]

here classes drill downwards , populate items:

public class item { public string title { get; set; } public string pubdate { get; set; } public ilist<attr> attr { get; set; } } public class attr { public attributes attribs { get; set; } } public class attributes { public string name { get; set; } public string value { get; set; } }

when count on item.attr, proper # if seek name/value of attributes in list, gives me null error. i've done lot of research , have been unable determine why it's creating appropriate items in list not values within item.

any thoughts?

since @attributes not valid property name in c#, need utilize [jsonproperty] attribute map json, e.g.:

public class attr { [jsonproperty("@attributes")] public attributes attribs { get; set; } }

c# json parsing json.net

No comments:

Post a Comment