1
    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=BingMapsKey

我上面的代码有什么问题吗?

4

2 回答 2

5

只需更改此行以使用 JSON 而不是 XML 格式进行查询

所以从这...

string query = "http://dev.virtualearth.net/REST/v1/Locations/" +         
               queryString + "?output=xml" + " &key=" + BingMapsKey;

对此...

string query = "http://dev.virtualearth.net/REST/v1/Locations/" +
               queryString + "?output=json" + " &key=" + BingMapsKey;

即只需更改output=xmloutput=json

于 2013-03-07T22:02:51.060 回答
0

一旦我将RootObject代码中的 undefined 替换为在Bing Maps REST Service .NET LibrariesBingMapsRESTService.Common.JSON.Response中找到的类型(@rbrundritt 建议您在其他帖子中使用),此代码对我来说运行良好

于 2012-09-01T21:29:58.090 回答