asp.net mvc 4 - {"No parameterless constructor defined for type of 'System.String[]'."} while deserailsing json data -


this controller

[nocache]     public actionresult saveassociate(string data)     {         javascriptserializer json = new javascriptserializer();         list<string> mystring = json.deserialize<list<string>>(data);         return content("hai");     } 

expression data value :

[{"assetname":"8888","assetnumber":"8888","classification":null,"parentasset":null,"serialnumber":"8888","parentcompany":"jpl holdings","barcode":null,"rfidtags":null,"assetid":"dfe2ae51-f153-4a67-bd3b-0114d8a40751","notes":null,"manufacturer":null,"departmentid":null,"department":null,"supplierid":null,"supplier":null},{"assetname":"552014","assetnumber":"552014","classification":null,"parentasset":"8888","serialnumber":"552014","parentcompany":"jpl holdings","barcode":null,"rfidtags":null,"assetid":"4109ba40-af78-486a-a40e-1d14a2d7b42f","notes":null,"manufacturer":null,"departmentid":null,"department":null,"supplierid":null,"supplier":null},{"assetname":"201","assetnumber":"201","classification":null,"parentasset":null,"serialnumber":"2011","parentcompany":"jpl holdings","barcode":null,"rfidtags":null,"assetid":"3e552280-16df-4c17-a4a5-1f61c4c96835","notes":null,"manufacturer":null,"departmentid":null,"department":null,"supplierid":null,"supplier":null}] 

at line list<string> mystring = json.deserialize<list<string>>(data); getting

{"no parameterless constructor defined type of 'system.string[]'."} 

even tried this

 [serializable] public class getuser {     public getuserdata[] data { get; set; } }  [serializable] public class getuserdata {     public string assetname { get; set; }     public string assetnumber { get; set; }     public string classification { get; set; }     public string parentasset { get; set; }     public string serialnumber { get; set; }     public string parentcompany { get; set; }     public string barcode { get; set; }     public string rfidtags { get; set; }     public string assetid { get; set; }     public string notes { get; set; }     public string manufacturer { get; set; }     public string departmentid { get; set; }     public string department { get; set; }     public string supplierid { get; set; }     public string supplier { get; set; } } 

controller

 public actionresult saveassociate(string data)     {         javascriptserializer json = new javascriptserializer();         getuser mystring = json.deserialize<getuser>(data);         return content("hai");     } 

am getting error type 'assettrackingsystem.model.getuser' not supported deserialization of array.

help me

instead of above code, try:

 public actionresult saveassociate(string data)  {     javascriptserializer json = new javascriptserializer();     getuserdata[] myusers = json.deserialize<getuserdata[]>(data);     return content("hai");   } 

because json sent array of object not object of array. hope you.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -