I have a json array as below
{
"odata.metadata": "https://testapp.mycomp.com/$metadata#UnitDetail",
"value": [
{
"Id": 1,
"UnitId": 238905,
"Active": false,
"Name": "Rakesh",
"ContactNumber": "0070002934"
},
{
"Id": 2,
"UnitId": 238906,
"Active": true,
"Name": "Rahul",
"ContactNumber": "123444003"
},
{
"Id": 3,
"UnitId": 238907,
"Active": true,
"Name": "Rohit",
"ContactNumber": "1227032932"
}
]
}
I am trying to deserialize it into c# list as below
var data= JsonConvert.DeserializeObject<UnitDetail[]>(json);
My c# class is a below
public class UnitDetail
{
public int Id { get; set; }
public int UnitId { get; set; }
public bool Active { get; set; }
public string Name { get; set; }
public string ContactNumber { get; set; }
}
But this code is not deserializing it.
I have also tried codes as below but none seems working
JavaScriptSerializer js = new JavaScriptSerializer();
UnitDetail[] serializedData= js.Deserialize<UnitDetail[]>(json);
and also like below
List<UnitDetail> serializedData= js.Deserialize<List<UnitDetail>>(json);
I am really not sure why it is not working. Any help would really be appriciable.
Thanks
List<UnitDetail> serializedData= js.Deserialize<List<UnitDetail>>(json);This seems to be fine.