Dear Sir
Error
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'GPSDATA.Form1+Root[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'CustomerId', line 1, position 14.
Please help me out for binding GridView.
Response
{
"CustomerId": XXXXXX,
"TransactionDetails": [
{
"ProcessingDateTime": "2023-04-22T06:14:28.850+05:30",
"TransactionDateTime": "2023-04-22T06:13:04+05:30",
"TransactionAmount": 480.0000,
"TransactionId": 2428777455,
"HexTagId": "34161FA82032897212913BA0",
"VehicleNumber": null,
"LaneCode": "Lane16",
"PlazaCode": "312049",
"TransactionStatus": "POSTED",
"TransactionReferenceNumber": "01000C1988954617790675",
"PlazaName": "Karman Toll Plaza"
},
{
"ProcessingDateTime": "2023-04-22T04:48:05.853+05:30",
"TransactionDateTime": "2023-04-22T04:47:16+05:30",
"TransactionAmount": 525.0000,
"TransactionId": 2428682329,
"HexTagId": "34161FA82032897212913BA0",
"VehicleNumber": null,
"LaneCode": "Lane13",
"PlazaCode": "062002",
"TransactionStatus": "POSTED",
"TransactionReferenceNumber": "002727135070",
"PlazaName": "Mahuvan Toll Plaza"
},
{
"ProcessingDateTime": "2023-04-22T04:19:15.690+05:30",
"TransactionDateTime": "2023-04-22T04:18:50+05:30",
"TransactionAmount": 290.0000,
"TransactionId": 2428653144,
"HexTagId": "34161FA82032897212913BA0",
"VehicleNumber": null,
"LaneCode": "L06",
"PlazaCode": "320052",
"TransactionStatus": "POSTED",
"TransactionReferenceNumber": "0010012304220419156210",
"PlazaName": "Raibha toll plaza"
},
{
"ProcessingDateTime": "2023-04-22T03:28:37.007+05:30",
"TransactionDateTime": "2023-04-22T03:28:24+05:30",
"TransactionAmount": 345.0000,
"TransactionId": 2428606278,
"HexTagId": "34161FA82032897212913BA0",
"VehicleNumber": null,
"LaneCode": "LANE03",
"PlazaCode": "125003",
"TransactionStatus": "POSTED",
"TransactionReferenceNumber": "002727057250",
"PlazaName": "Baretha or Jajau"
},
],
"TotalPages": null,
"CurrentPageNumber": null,
"NoofTxnsForEachPage": null,
"TotalTransactions": null,
"VehicleNumber": "RJ32GC6728"
}
Class
public class Root
{
public int CustomerId { get; set; }
public object TotalPages { get; set; }
public object CurrentPageNumber { get; set; }
public object NoofTxnsForEachPage { get; set; }
public object TotalTransactions { get; set; }
public string VehicleNumber { get; set; }
public List<TransactionDetail> TransactionDetails { get; set; }
}
public class TransactionDetail
{
public DateTime ProcessingDateTime { get; set; }
public DateTime TransactionDateTime { get; set; }
public double TransactionAmount { get; set; }
public long TransactionId { get; set; }
public string HexTagId { get; set; }
public object VehicleNumber { get; set; }
public string LaneCode { get; set; }
public string PlazaCode { get; set; }
public string TransactionStatus { get; set; }
public string TransactionReferenceNumber { get; set; }
public string PlazaName { get; set; }
}
Code for Binding
IRestResponse result = restClient.Execute(request);
Root[] pd = JsonConvert.DeserializeObject<Root[]>(result.Content);
if (pd != null)
{
GridView1.DataSource = pd[0].TransactionDetails;
GridView1.AutoGenerateColumns = true;
}