0

This is my 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 this line List<string> mystring = json.Deserialize<List<string>>(data); am getting

{"No parameterless constructor defined for type of 'System.String[]'."} 

even i tried like 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' is not supported for deserialization of an array.

Help me

6
  • 1
    I don't know ASP.net so I won't post any answers. I do question why you're saying List should be string when it is supposed to hold the return of a deserialization (which I assume would be an object or array or something) Commented May 17, 2014 at 11:57
  • Plz check my edit above Commented May 17, 2014 at 11:58
  • I've read the edit, my question still stands (with the caveat that I don't really know much about what I'm looking at). Deserialize shouldn't return a string, but your type casting and var names imply that you expect it to. The docs ( msdn.microsoft.com/en-us/library/bb355316(v=vs.110).aspx ) say it returns "The deserialized object." Commented May 17, 2014 at 12:00
  • forums.asp.net/t/1713640.aspx and stackoverflow.com/questions/15699395/… this site shows it works..i followed this Commented May 17, 2014 at 12:05
  • 1
    I don't know--I was hoping my observation might be helpful to you, but I have no idea how accurate it may have been. Commented May 17, 2014 at 12:15

1 Answer 1

1

Instead of the above code, could you try:

 public ActionResult SaveAssociate(string data) { JavaScriptSerializer json = new JavaScriptSerializer(); GetUserdata[] myUsers = json.Deserialize<GetUserdata[]>(data); return Content("Hai"); } 

Because your Json is sent as an array of object not an object of array. I hope it will help you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.