Unexpected JSON token when reading DataTable. Expected StartArray, got StartObject. Path '', line 1, position 1.
{
"returnCode":0,
"returnMessage":"17 transaction(s) found",
"transactions":[
{
"amount":"300000",
"paymentDateAndTime":"2022-05-05 11:54:12",
"schoolpayReceiptNumber":"8292377",
"sourceChannelTransDetail":"CHANDIRU GRACE NYAMUGA",
"sourceChannelTransactionId":"69944484949",
"sourcePaymentChannel":"Airtel Money",
"studentName":"Priscilla Ndagire",
"studentPaymentCode":"1003233579",
"studentRegistrationNumber":"AC-05-05373",
"transactionCompletionStatus":"Completed"
},
{
"amount":"680000",
"paymentDateAndTime":"2022-05-05 11:56:44",
"schoolpayReceiptNumber":"8292484",
"sourceChannelTransDetail":"20009938132 - 1003233507 - Sharon Mukamba Biira",
"sourceChannelTransactionId":"AGENCY-SCHOOLPAY-98645071",
"sourcePaymentChannel":"Centenary Bank",
"studentName":"Sharon Mukamba Biira",
"studentPaymentCode":"1003233507",
"studentRegistrationNumber":"AC-05-05328",
"transactionCompletionStatus":"Completed"
}
]
}
System.Net.Http.HttpClient client = new HttpClient();
HttpResponseMessage result = await client.GetAsync("https://schoolpay.co.ug/paymentapi/AndroidRS/SyncSchoolTransactions/233/2022-05-05/3B91DB220B7797416DD5417B2A3AFC95");
// string myJson = await result.Content.ReadAsStringAsync();
string json = await result.Content.ReadAsStringAsync();
// var root = JsonConvert.DeserializeObject<Root>(json);
DataTable dt = JsonConvert.DeserializeObject<DataTable>(json);
// DataTable dtb;
if (dt.Rows.Count > 0)
{
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(con))
{
sqlBulkCopy.DestinationTableName = "dbo.Schoolpay";
sqlBulkCopy.ColumnMappings.Add("amount", "amount");
sqlBulkCopy.ColumnMappings.Add("Paymentdateandtime", "Paymentdateandtime");
sqlBulkCopy.ColumnMappings.Add("schoolpayreceiptno", "schoolpayreceiptno");
sqlBulkCopy.ColumnMappings.Add("sourcechanneltransdetail", "sourcechanneltransdetail");
sqlBulkCopy.ColumnMappings.Add("sourcepaymentchannel", "sourcepaymentchannel");
sqlBulkCopy.ColumnMappings.Add("studentname", "studentname");
sqlBulkCopy.ColumnMappings.Add("studentpaymentcode", "studentpaymentcode");
sqlBulkCopy.ColumnMappings.Add("studentregistrationnumber", "studentregistrationnumber");
sqlBulkCopy.ColumnMappings.Add("trannsactioncompletionstatus", "trannsactioncompletionstatus");
con.Open();
sqlBulkCopy.WriteToServer(dt);
con.Close();
}
}