Upon serializing the JSON if shows an error like this one. (Cannot deserialize the current JSON object (e.g. {""name"":""value""}) into type ‘System.Collections.Generic.List`1)
This is my code on serializing json
Dim test As List(Of properties) = Newtonsoft.Json.JsonConvert.DeserializeObject(Of List(Of properties))(response)
e.Result = test
This is my json:
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
174.886706,
-37.018018
]
},
"properties":{
"country_code":"nz",
"housenumber":"34",
"street":"Jellicoe Road",
"country":"New Zealand",
"county":"Auckland",
"datasource":{
"sourcename":"openaddresses",
"attribution":"© OpenAddresses contributors",
"license":"BSD-3-Clause License"
},
"state":"Auckland Region",
"district":"Auckland",
"city":"Manurewa",
"lon":174.886706,
"lat":-37.018018,
"postcode":"2102",
"formatted":"34 Jellicoe Road, Manurewa 2102, New Zealand",
"address_line1":"34 Jellicoe Road",
"address_line2":"Manurewa 2102, New Zealand",
"timezone":{
"name":"Pacific/Auckland",
"offset_STD":"+12:00",
"offset_STD_seconds":43200,
"offset_DST":"+13:00",
"offset_DST_seconds":46800,
"abbreviation_STD":"NZST",
"abbreviation_DST":"NZDT"
},
"plus_code":"4VJPXVJP+QM",
"result_type":"building",
"rank":{
"popularity":2.4928992206144494,
"confidence":0.95,
"match_type":"full_match"
},
"place_id":"5158e542e55fdc654059a25ef0694e8242c0c00203e2034b6f70656e6164647265737365733a616464726573733a6e7a2f636f756e747279776964652d6164647265737365732d636f756e7472792e6373763a38643534333962376163366334306438"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
175.766901,
-37.821629
]
},
"properties":{
"country_code":"nz",
"housenumber":"34",
"street":"Jellicoe Road",
"country":"New Zealand",
"county":"Matamata-Piako",
"datasource":{
"sourcename":"openaddresses",
"attribution":"© OpenAddresses contributors",
"license":"BSD-3-Clause License"
},
"state":"Waikato Region",
"city":"Matamata",
"lon":175.766901,
"lat":-37.821629,
"formatted":"34 Jellicoe Road, Matamata, New Zealand",
"address_line1":"34 Jellicoe Road",
"address_line2":"Matamata, New Zealand",
"county_code":"MP",
"timezone":{
"name":"Pacific/Auckland",
"offset_STD":"+12:00",
"offset_STD_seconds":43200,
"offset_DST":"+13:00",
"offset_DST_seconds":46800,
"abbreviation_STD":"NZST",
"abbreviation_DST":"NZDT"
},
"plus_code":"4VJQ5QH8+8Q",
"plus_code_short":"H8+8Q Matamata, Matamata-Piako, New Zealand",
"result_type":"building",
"rank":{
"popularity":0.6696517116786308,
"confidence":0.95,
"match_type":"full_match"
},
"place_id":"51a148f7738af8654059fc389a232be942c0c00203e2034b6f70656e6164647265737365733a616464726573733a6e7a2f636f756e747279776964652d6164647265737365732d636f756e7472792e6373763a33333631373562373065333363333362"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
174.743699,
-36.728367
]
},
"properties":{
"country_code":"nz",
"housenumber":"34",
"street":"Jellicoe Road",
"country":"New Zealand",
"county":"Auckland",
"datasource":{
"sourcename":"openaddresses",
"attribution":"© OpenAddresses contributors",
"license":"BSD-3-Clause License"
},
"state":"Auckland Region",
"district":"Auckland",
"city":"Murrays Bay",
"lon":174.743699,
"lat":-36.728367,
"formatted":"34 Jellicoe Road, Murrays Bay, New Zealand",
"address_line1":"34 Jellicoe Road",
"address_line2":"Murrays Bay, New Zealand",
"timezone":{
"name":"Pacific/Auckland",
"offset_STD":"+12:00",
"offset_STD_seconds":43200,
"offset_DST":"+13:00",
"offset_DST_seconds":46800,
"abbreviation_STD":"NZST",
"abbreviation_DST":"NZDT"
},
"plus_code":"4VMP7PCV+MF",
"plus_code_short":"CV+MF Murrays Bay, Auckland, New Zealand",
"result_type":"building",
"rank":{
"popularity":1.6904873504878504,
"confidence":0.95,
"match_type":"full_match"
},
"place_id":"512c62d861ccd7654059293e3e213b5d42c0c00203e2034b6f70656e6164647265737365733a616464726573733a6e7a2f636f756e747279776964652d6164647265737365732d636f756e7472792e6373763a35626333633734313932613434303664"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
174.021665,
-36.133486
]
},
"properties":{
"country_code":"nz",
"housenumber":"34",
"street":"Jellicoe Road",
"country":"New Zealand",
"county":"Kaipara",
"datasource":{
"sourcename":"openaddresses",
"attribution":"© OpenAddresses contributors",
"license":"BSD-3-Clause License"
},
"state":"Northland Region",
"city":"Ruawai",
"lon":174.021665,
"lat":-36.133486,
"formatted":"34 Jellicoe Road, Ruawai, New Zealand",
"address_line1":"34 Jellicoe Road",
"address_line2":"Ruawai, New Zealand",
"county_code":"KP",
"timezone":{
"name":"Pacific/Auckland",
"offset_STD":"+12:00",
"offset_STD_seconds":43200,
"offset_DST":"+13:00",
"offset_DST_seconds":46800,
"abbreviation_STD":"NZST",
"abbreviation_DST":"NZDT"
},
"plus_code":"4VMPV28C+JM",
"result_type":"building",
"rank":{
"popularity":0.35600631140076516,
"confidence":0.95,
"match_type":"full_match"
},
"place_id":"51f94ecc7ab1c0654059a73cba11161142c0c00203e2034b6f70656e6164647265737365733a616464726573733a6e7a2f636f756e747279776964652d6164647265737365732d636f756e7472792e6373763a36636333363832386437663931623964"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
174.021564,
-36.13336
]
},
"properties":{
"country_code":"nz",
"housenumber":"34A",
"street":"Jellicoe Road",
"country":"New Zealand",
"county":"Kaipara",
"datasource":{
"sourcename":"openaddresses",
"attribution":"© OpenAddresses contributors",
"license":"BSD-3-Clause License"
},
"state":"Northland Region",
"city":"Ruawai",
"lon":174.021564,
"lat":-36.13336,
"formatted":"34A Jellicoe Road, Ruawai, New Zealand",
"address_line1":"34A Jellicoe Road",
"address_line2":"Ruawai, New Zealand",
"county_code":"KP",
"timezone":{
"name":"Pacific/Auckland",
"offset_STD":"+12:00",
"offset_STD_seconds":43200,
"offset_DST":"+13:00",
"offset_DST_seconds":46800,
"abbreviation_STD":"NZST",
"abbreviation_DST":"NZDT"
},
"plus_code":"4VMPV28C+MJ",
"result_type":"building",
"rank":{
"popularity":0.35600631140076516,
"confidence":0.95,
"match_type":"full_match"
},
"place_id":"51ac58fca6b0c06540591b4cc3f0111142c0c00203e2034b6f70656e6164647265737365733a616464726573733a6e7a2f636f756e747279776964652d6164647265737365732d636f756e7472792e6373763a36653039366639653964306338646336"
}
}
],
"query":{
"text":"34C Jellicoe Road",
"parsed":{
"housenumber":"34c",
"street":"jellicoe road",
"expected_type":"building"
}
}
}
And this is my model:
Public Class AutoCompleteResponse
Public Property type As String
Public Property features As String
Public Property Properties As IList(Of properties)
End Class
Public Class properties
'Public Property place_id As String
Public Property country_code As String
Public Property housenumber As String
Public Property street As String
Public Property country As String
Public Property county As String
Public Property state As String
Public Property district As String
Public Property city As String
Public Property lon As String
Public Property lat As String
Public Property postcode As String
Public Property formatted As String
Public Property address_line1 As String
Public Property address_line2 As String
Public Property plus_code_short As String
Public Property plus_code As String
Public Property result_type As String
Public Property rank As String
Public Property place_id As String
End Class
I just don’t know why it shows me that error.
2
Answers
my mistake is inside my class and rewrite it with the help of https://jsonutils.com/ just paste your json file on there then convert to c# or vb.net
Your AutoCompleteResponse class expects "features" to be a string, but in your json "feature" is much more complex than just a string. To reflect the complexity of the data of "feature" in your code, you need to make a class for it. Then in the AutoCompleteResponse class, features will be a list of these classes.
Here’s how the feature class could look: