Google的Geocode API会返回一个奇怪的响应(二进制文件?)

时间:2014-01-06 15:36:25

标签: api google-maps geocoding

我正在尝试通过此API调用获得响应:

http://maps.googleapis.com/maps/api/geocode/json?address=rua+silva+jardim+1161+santa+luzia+mg&language=pt-br&sensor=false

在浏览器网站上,响应正常。但是当我使用这种方法时:

private static string GetResultString(string geocodingUrlApi)
  {
    HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(geocodingUrlApi);
    webRequest.Method = "GET";
    webRequest.ContentType = "application/json";
    webRequest.UserAgent = "WayMoto 1.0";

    HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
    StreamReader reader = new StreamReader(webResponse.GetResponseStream());

    string response = reader.ReadToEnd();
    return response;
  }

内容方法参数geocodingUrlApi: Content of geocodingUrlApi

回复内容var: Content of response

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您返回的数据类型是json对象(不是字符串):application / json。

以下是Microsoft在C#中反序列化REST API调用中返回的json对象的文章。

http://msdn.microsoft.com/en-us/library/hh674188.aspx