我正在尝试使用 SmartyStreets JSON LiveAddress API,但遇到了一些困难。我承认我对 JSON 不太熟悉。无论如何,我尝试了几种不同的方法,但通常会出现错误“无法将 JSON 数组反序列化为元数据类型”。
这是 JSON 字符串:
[{"input_index":0,"candidate_index":0,"delivery_line_1":"1600 Amphitheatre Pkwy","last_line":"Mountain View CA 94043-1351","delivery_point_barcode":"940431351000","components":{"primary_number":"1600","street_name":"Amphitheatre","street_suffix":"Pkwy","city_name":"Mountain View","state_abbreviation":"CA","zipcode":"94043","plus4_code":"1351","delivery_point":"00","delivery_point_check_digit":"0"},"metadata":{"record_type":"S","county_fips":"06085","county_name":"Santa Clara","carrier_route":"C058","congressional_district":"14"},"analysis":{"dpv_match_code":"Y","dpv_footnotes":"AABB","dpv_cmra":"N","dpv_vacant":"N","ews_match":false,"footnotes":"N#"}}]
我使用jsontocsharp webapp 来创建类。
这是我正在使用的代码:
using (var webClient = new WebClient())
{
var json = webClient.DownloadString("url");
var md = JsonConvert.DeserializeObject<Metadata>(json);
litTest.Text = md.county_name;
}
然后抛出我上面提到的错误。
任何帮助将不胜感激。
谢谢你,安德鲁