c# - Issues deserialising JSON -


i have json data shown here:

[ {"article":     {         "articleid":0,         "engtitle":"area of interest",         "engexcerpt":"",         "engbody":"",         "articletag":             {                 "tagattribute1":"selection",                 "tagattribute2":"areaofinterest"             }     } } ] 

which me looks fine when gets passed method on deserializeobject called, results in error.

here code have deserialize object:

list<articlejson> lstarticlejson = jsonconvert.deserializeobject<list<articlejson>>(jsondata); 

and here relevant models:

public class articlejson {     public article article { get; set; } }  public partial class article : basemodel { public article()     {         this.articletag = new hashset<articletag>();     }      public string engtitle { get; set; }     public string engexcerpt { get; set; }     public string engbody { get; set; }     public virtual ienumerable<articletag> articletag { get; set; } }  public partial class articletag : basemodel {         public string tagattribute1 { get; set; }     public string tagattribute2 { get; set; } } 

i cannot see need change rectify error getting thrown:-

cannot deserialize current json object (e.g. {"name":"value"}) type 'system.collections.generic.ienumerable`1[model.articletag]' because type requires json array (e.g. [1,2,3]) deserialize correctly.

to fix error either change json json array (e.g. [1,2,3]) or change deserialized type normal .net type (e.g. not primitive type integer, not collection type array or list) can deserialized json object. jsonobjectattribute can added type force deserialize json object.

path '[0].article.articletag.tagattribute1', line 1, position 1538.

try changing json edit:

"articletag": [      {"tagattribute1":"selection",      "tagattribute2":"areaofinterest"} ] 

it's because have ienumerable<articletag> though sending 1 object, need still specify json array binder happy.

in same way can't in c#

ienumerable<foo> foos = new foo(); 

the error posted tells this:

to fix error either change json json array (e.g. [1,2,3]) or change deserialized type normal .net type (e.g. not primitive type integer, not collection type array or list) can deserialized json object. jsonobjectattribute can added type force deserialize json object.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -