2014-01-06 22 views
0

我想從這個API呼叫響應:谷歌的地理編碼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

內容: Content of response

感謝您的幫助。

+0

看起來像一個字符編碼問題。 – geocodezip

回答

0

您返回的數據類型是一個json對象(不是字符串):application/json。

下面是Microsoft爲C#反編譯REST API調用中返回的JSON對象的文章。

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

+0

即使刪除contentType,我也有同樣的行爲,如果這是問題,我不相信,因爲我不想在當時反序列化響應。我想要的是以字符串的形式獲得響應。 –

相關問題