我正在尝试使用 Google Mapping API 使用邮政编码获取地址。到目前为止,我可以从响应中获取 JSON 数据并将其存储在“var”中。
但是,我无法将街道、城镇和县等字段提取到理想情况下,将它们分别提取为单独的字符串变量。
到目前为止,这是我的代码。
string postcode = Convert.ToString(tbPostcode.Text);
string searchCode = "http://maps.googleapis.com/maps/api/geocode/json?address=" + postcode + "&sensor=false";
var result = "";
var httpWebRequest = (HttpWebRequest)WebRequest.Create(searchCode);
httpWebRequest.ContentType = "text/json";
httpWebRequest.Method = "POST";
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write("");
streamWriter.Flush();
streamWriter.Close();
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
}
}
MessageBox.Show(result);
希望有人能帮忙,谢谢!
亚当