我正在尝试从这个API调用中获得响应:
http://maps.googleapis.com/maps/api/geocode/json?address=rua+silva+jardim+1161+santa+luzia+mg&language=pt-br&sensor=false
在浏览器站点上,响应是ok的。但是当我使用这个方法时:
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:
响应变量的内容:
谢谢你的帮助。
发布于 2014-01-07 01:35:08
返回的数据类型是一个json对象(不是字符串):application/json。
这是微软为C#撰写的一篇文章,内容是对REST API调用中返回的json对象进行反序列化。
http://msdn.microsoft.com/en-us/library/hh674188.aspx
https://stackoverflow.com/questions/20953425
复制相似问题