Hi Sir
I have an issue when using external api url. Error is
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
Private Sub POST_TEST_DATA()
Dim url = New RestClient("http://avalon.insignianetworks.cloud/srcargo/rest/getBookingList")
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
url.Timeout = -1
'Dim request = New RestRequest(Method.POST)
Dim request = New RestRequest(Method.GET)
request.AddHeader("Authorization", "Bearer 31|L1JWTR9MgAahBMn7PhbNbc7fzttmYVFJI9dDNhRo")
Dim response As IRestResponse = url.Execute(request)
Dim json As String = response.Content
Dim res As BouncesAndBlocks = JsonConvert.DeserializeObject(Of BouncesAndBlocks)(json) '' original
For Each bouncesAndBlock In res.data
Try
Dim conString As String = ConfigurationManager.ConnectionStrings("ConnectString").ConnectionString
Dim query As String = "INSERT INTO Red_X_temp " &
"(sname, saddress1, saddress2, scity, spostcode, sstate," &
"dairport, scountry, detailOfContent, weight, productPackages, " &
"dimensionX, dimensionY, dimensionZ, chargeableRate, rname, rphone, " &
"raddress1, raddress2, rpostcode, rcity, rstate, rairport, rcountry, " &
"rremark, rvia, serviceModeId, agentId, trackingno)" &
"VALUES" &
"(@sname, @saddress1, @saddress2, @scity, @spostcode, @sstate," &
"@dairport, @scountry, @detailOfContent, @weight, @productPackages, " &
"@dimensionX, @dimensionY, @dimensionZ, @chargeableRate, @rname, @rphone, " &
"@raddress1, @raddress2, @rpostcode, @rcity, @rstate, @rairport, @rcountry, " &
"@rremark, @rvia, @serviceModeId, @agentId, @trackingno)"
Using con As SqlConnection = New SqlConnection(conString)
Dim cmd As SqlCommand = New SqlCommand(query, con)
cmd.Parameters.AddWithValue("@sname", bouncesAndBlock.sname)
cmd.Parameters.AddWithValue("@saddress1", bouncesAndBlock.saddress1)
cmd.Parameters.AddWithValue("@saddress2", bouncesAndBlock.saddress2)
cmd.Parameters.AddWithValue("@scity", bouncesAndBlock.scity)
cmd.Parameters.AddWithValue("@spostcode", bouncesAndBlock.spostcode)
cmd.Parameters.AddWithValue("@sstate", bouncesAndBlock.sstate)
cmd.Parameters.AddWithValue("@dairport", bouncesAndBlock.dairport)
cmd.Parameters.AddWithValue("@scountry", bouncesAndBlock.scountry)
cmd.Parameters.AddWithValue("@detailOfContent", bouncesAndBlock.detailOfContent)
cmd.Parameters.AddWithValue("@weight", bouncesAndBlock.weight)
cmd.Parameters.AddWithValue("@productPackages", bouncesAndBlock.productPackages)
cmd.Parameters.AddWithValue("@dimensionX", bouncesAndBlock.dimensionX)
cmd.Parameters.AddWithValue("@dimensionY", bouncesAndBlock.dimensionY)
cmd.Parameters.AddWithValue("@dimensionZ", bouncesAndBlock.dimensionZ)
cmd.Parameters.AddWithValue("@chargeableRate", bouncesAndBlock.chargeableRate)
cmd.Parameters.AddWithValue("@rname", bouncesAndBlock.rname)
cmd.Parameters.AddWithValue("@rphone", bouncesAndBlock.rphone)
cmd.Parameters.AddWithValue("@raddress1", bouncesAndBlock.raddress1)
cmd.Parameters.AddWithValue("@raddress2", bouncesAndBlock.raddress2)
cmd.Parameters.AddWithValue("@rpostcode", bouncesAndBlock.rpostcode)
cmd.Parameters.AddWithValue("@rcity", bouncesAndBlock.rcity)
cmd.Parameters.AddWithValue("@rstate", bouncesAndBlock.rstate)
cmd.Parameters.AddWithValue("@rairport", bouncesAndBlock.rairport)
cmd.Parameters.AddWithValue("@rcountry", bouncesAndBlock.rcountry)
cmd.Parameters.AddWithValue("@rremark", bouncesAndBlock.rremark)
cmd.Parameters.AddWithValue("@rvia", bouncesAndBlock.rvia)
cmd.Parameters.AddWithValue("@serviceModeId", bouncesAndBlock.serviceModeId)
cmd.Parameters.AddWithValue("@agentId", bouncesAndBlock.agentId)
cmd.Parameters.AddWithValue("@trackingno", bouncesAndBlock.trackingNo)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Using
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert", "alert('Record Saved !');", True)
Catch ex As Exception
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "alert", "alert('Record wrong !');", True)
End Try
Next
End Sub
[
{
"id": 120,
"trackingNo": "683123690493",
"sname": "AMAN SALES SDN BHD",
"sphone": "019-8824500",
"saddress1": "NO 39/39A,JALAN 23 TAMAN",
"saddress2": "BUKIT KUCHAI",
"scity": "PUCHONG",
"spostcode": "47100",
"sstate": "Selangor",
"dairport": "KUL",
"scountry": "MY",
"detailOfContent": "PARTS",
"weight": 5.0,
"productPackages": 1,
"dimensionX": 40.0,
"dimensionY": 28.0,
"dimensionZ": 26.0,
"chargebleRate": 5.0,
"rname": "AMAN SALES & SERVICES (M) SDN BHD",
"rphone": "089-880757",
"raddress1": "LOT13 NEW KIMBELL INDUSTRIAL",
"raddress2": "ESTATE,MDLD 4974,JALAN KIMBELL 91100",
"rpostcode": "91100",
"rcity": "LAHAD DATU",
"rstate": "Sabah",
"rairport": "LDU",
"rcountry": "MY",
"rremark": "PLEASE DEL ASAP",
"rvia": "BKI",
"serviceModeId": null,
"agentId": null
}
]
Pls advice me
Thank you
Maideen
Below is what I have tried.