vb.net - I am trying to deserialize a JSON but Newtonsoft.Json is throwing this error -


cannot deserialize current json object (e.g. {"name":"value"}) type 'retail_web.helpers+sale1[]' because type requires json array (e.g. [1,2,3]) deserialize correctly.
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 'sale.saleid', line 1, position 73.

json :

{     "sale": {         "saleid": "54",         "timestamp": "2016-06-10t13:03:16+00:00",         "discountpercent": "0"     } } 

model :

public class helpers     public property sale sales()      public class sales          public property saleid string         public property timestamp string         public property discountpercent string         public property completed string     end class end class 

and, code causing error :

dim ordersreceiptlist2 helpers  ordersreceiptlist2 = jsonconvert.deserializeobject(of helpers)(file.readalltext("c:\test.json")) msgbox(ordersreceiptlist2.sale(0).saleid) 

sale not array. try instead :

public class helpers     public property sale sales 'removed ()      public class sales          public property saleid string         public property timestamp string         public property discountpercent string         public property completed string     end class end class 

msgbox(ordersreceiptlist2.sale.saleid) 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -