Click here to Skip to main content
14,920,094 members
Please Sign up or sign in to vote.
3.67/5 (2 votes)
See more:
Hai I have json string like this


public class Details
       public string StudentId { get; set; }
       public string RollNo { get; set; }

Details result = JsonConvert.DeserializeObject<details>(str);

but error showing like this

Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'AdmissionService+Details' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.

Can anyone help???
Updated 25-Feb-14 23:02pm

Please try is as below.

List<Details> data = JsonConvert.DeserializeObject<List<Details>>(jsonString);

NOTE: I hope you're using json.NET.
Faisalabadians 26-Feb-14 8:17am
as presented JSON is array then there should be an array or list of Details
Sampath Lokuge 26-Feb-14 8:19am
Yep,Thanks Faisalabadians. :)
Try this
JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
Details objDetails  = jsonSerializer.Deserialize<details>(jsonInput)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900