如何转换JSON(无法将当前JSON对象(例如{"“name””:““value”"})转换为类型“System.Collections.Generic.List”1)

djp7away  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(104)

序列化JSON时,如果显示类似这样的错误。(无法将当前JSON对象(例如{"“name””:““value”"})重命名为类型“System.Collections.Generic.List”1“)
这是我的代码序列化json

Dim test As List(Of properties) = Newtonsoft.Json.JsonConvert.DeserializeObject(Of List(Of properties))(response)
e.Result = test

字符串
这是我的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"
      }
   }
}


这是我的模型:

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


我只是不知道为什么它会显示这个错误。

fzwojiic

fzwojiic1#

你的AutoCompleteResponse类期望“features”是一个字符串,但在你的json中“feature”比字符串复杂得多。为了反映代码中“feature”数据的复杂性,你需要为它创建一个类。然后在AutoCompleteResponse类中,features将是这些类的列表。
以下是要素类的外观:

Public Class Feature
    Public Property type As String
    Public Property geometry As Geometry
    Public Property properties As Properties
End Class

字符串

相关问题