This project has moved and is read-only. For the latest updates, please go here.

Convert Json of Array

Jan 19, 2009 at 5:48 AM

I am having problem converting the Json File with array into C# object
Following is the Json String which I am trying to convert

string json2 = "{\"Drivers\":[{\"FirstName\":\"G1\",\"LastName\":\"R1\"},{\"FirstName\":\"S1\",\"LastName\":\"A1\"}]}";

Below is the code to convert to C# Object

public class Driver
        public string FirstName { get; set; }
        public string LastName { get; set; }

List<Driver> deserializedDrivers = (List<Driver>)JsonConvert.DeserializeObject(json2, typeof(List<Driver>));          

The above code does not for the string json2
But if you use below string the above code will work flawless.

string json1 = "{\"FirstName\":\"G1\",\"LastName\":\"R1\"},{\"FirstName\":\"S1\",\"LastName\":\"A1\"}";

Can you give me suggestion to convert json2 string into C# array object.

Thanks & Regards,