Reputation: 151
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);
}
}
Is there anything wrong in my in the codes above?
Upvotes: 1
Views: 6608
Reputation: 3979
Just change this line for make the query with JSON and not XML format
So from this ...
string query = "http://dev.virtualearth.net/REST/v1/Locations/" +
queryString + "?output=xml" + " &key=" + BingMapsKey;
To this ...
string query = "http://dev.virtualearth.net/REST/v1/Locations/" +
queryString + "?output=json" + " &key=" + BingMapsKey;
i.e. just change output=xml
to output=json
Upvotes: 5
Reputation: 23754
This code is working fine for me once I replace the undefined RootObject
in your code with the BingMapsRESTService.Common.JSON.Response
type found in the Bing Maps REST Service .NET Libraries that @rbrundritt suggested you use in your other post
Upvotes: 0