Ошибка десериализации Newtonsoft json
Hi, I am trying to use Newtonsoft JSon to deserialize to my class, but receives an error: Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in Newtonsoft.Json.dll Exception thrown: 'Newtonsoft.Json.JsonSerializationException' in System.Private.CoreLib.dll
Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'PassatRep.LocIQRoot' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly. To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. Path '', line 1, position 1.'
Debug returns the following [{"place_id":"83003376","licence":"\u00a9 LocationIQ.com CC BY 4.0, Data \u00a9 OpenStreetMap contributors, ODbL 1.0","osm_type":"way","osm_id":"27462943","boundingbox":["55.3283734","55.3284947","8.7620641","8.7623819"],"lat":"55.3283734","lon":"8.7620641","display_name":"Torvet, Ribe, Esbjerg Municipality, Region of Southern Denmark, 6760, Denmark","class":"highway","type":"pedestrian","importance":0.31}] Here is a link to the website where the Json response is located
What is wrong with the Json response? Thank you in advance Here is my class
<pre>Public Class LocationIQ Public Shared Async Function GetLocationIQ(ByVal SearchFor As String) As Task(Of LocIQRoot) Debug.WriteLine(Keys.LocationIQKey) Dim httpn = New HttpClient() Dim url As String = "https://eu1.locationiq.com/v1/search.php?key=" & Keys.LocationIQKey & "&q=" & SearchFor & "&format=json" Dim response As HttpResponseMessage = Await httpn.GetAsync(url) Dim result = Await response.Content.ReadAsStringAsync() Debug.WriteLine(result) Dim data As LocIQRoot = JsonConvert.DeserializeObject(Of LocIQRoot)(result) Return data End Function End Class Public Class LocIQRoot Public Property Loc() As LocIQ End Class Public Class LocIQ ' https://locationiq.com/docs#forward-geocoding Public Property place_id As String Public Property licence As String Public Property osm_type As String Public Property osm_id As String Public Property boundingbox As List(Of String) Public Property lat As String Public Property lon As String Public Property display_name As String Public Property IQclass As String Public Property type As String Public Property importance As Double Public Property icon As String End Class Private Async Sub btnTest3_Click(sender As Object, e As RoutedEventArgs) Handles btnTest3.Click Dim aa As LocIQRoot = Await LocationIQ.GetLocationIQ("Torvet 1 28 ribe") End Sub
Что я уже пробовал:
I have tried to fix this error, but I think it has something to with the way this Json response is presented