public async void MakeRequest(string requestUrl)
{
try
{
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
using (HttpWebResponse response = await request.GetResponseAsync() as HttpWebResponse)
{
if (response.StatusCode != HttpStatusCode.OK)
throw new Exception(string.Format(
"Server error(HTTP {0}:{1}.",
response.StatusCode,
response.StatusDescription));
DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(RootObject));
object objResponse = jsonSerializer.ReadObject(response.GetResponseStream());
root = (RootObject)objResponse;
if (root == null)
this.Frame.Navigate(typeof(MainPage));
}
}
catch (Exception ex)
{
ThrowException(ex);
}
}
鏈接:http://dev.virtualearth.net/REST/V1/Routes?wp.0=39.920829,32.853883&wp.1=39.877666,32.864728&key=BingMapsKeyREST服務 - 反序列化JSON錯誤:遇到意外的字符 '<'
有什麼錯誤的,我在上面的代碼?
沒有改變。 –
嗯...我剪切和粘貼你的代碼就像它,並拋出一個按鈕後面。我已將我的VS2012項目放在DropBox上,位於https://www.dropbox.com/s/hoiszqnhwivuim2/jsondeser.zip - 放入Bing密鑰,看看會發生什麼。該應用程序沒有做任何事情,但是您可以在ReadObject的返回中放置一個斷點以查看數據。 –