我試圖消費SmartyStreets JSON LiveAddress API,我有一些困難。我承認我對JSON不太熟悉。無論如何,我已經嘗試了幾種不同的方法,通常最終會出現錯誤「無法將JSON數組反序列化爲類型元數據」。試圖消費SmartyStreets JSON與JSON.Net ...「不能反序列化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#"}}]
我使用的web應用程序jsontocsharp創建類。
這裏是我使用的代碼:
using (var webClient = new WebClient())
{
var json = webClient.DownloadString("url");
var md = JsonConvert.DeserializeObject<Metadata>(json);
litTest.Text = md.county_name;
}
然後引發我上面提到的錯誤。
任何援助將不勝感激。
謝謝 安德魯
太棒了。我一定要更多地關注動態類。謝謝你指向我的動態Json對象和例子......你真的幫助我了! – ajtatum 2012-03-01 21:12:31
不客氣。 – 2012-03-01 21:14:44
@ L.B你是如何格式化的? – 2012-03-01 22:40:05