none
{"There was an error deserializing the object of type *****. Encountered unexpected character 'ÿ'."} RRS feed

  • Question

  • I get this message  when I try to fure the Getresponse method

    here is a the code

    private async void GetMap()
            {
                Response r = null;
                Uri routeRequest = null; 
    
                routeRequest = RouteRequest("mapLayer=TrafficFlow");
                r = await GetResponse(routeRequest);
                if (r != null &&
                      r.ResourceSets != null &&
                      r.ResourceSets.Length > 0 &&
                      r.ResourceSets[0].Resources != null &&
                      r.ResourceSets[0].Resources.Length > 0)
                {
                   //
    
                }
    
            }
    
            private Uri RouteRequest(string Query)
            {
                Uri routeRequest = new Uri(
                                 string.Format("http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/Bellevue%20Washington?mapLayer=TrafficFlow&key={1}",
                                 Query, sessionKey));
                
                return routeRequest;
            }
    
            private async Task<Response> GetResponse(Uri uri)
            {
    
                System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
                var response = await client.GetAsync(uri);
                using (var stream = await response.Content.ReadAsStreamAsync())
                {
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Response));
                    return ser.ReadObject(stream) as Response;
                }
            }

    Monday, May 26, 2014 2:57 PM

Answers

  • In the RouteRequest method you are setting the Bing Maps key to "maplayer=TrafficFlow" instead of to your session key. This is causing the URI request to return a 401 error. Try fixing the string.format and seeing if you still get this error.

    http://rbrundritt.wordpress.com

    Monday, May 26, 2014 6:27 PM
  • Ok, so, originally I thought you were trying to get imagery metadata, but the URL you are using is to get a static image. You don't use the JSON data contracts when requesting a static image. The JSON data contracts are for JSON data. Simply load the URL into an Image object, or load it in a browser window.

    http://rbrundritt.wordpress.com

    Monday, May 26, 2014 7:45 PM

All replies

  • In the RouteRequest method you are setting the Bing Maps key to "maplayer=TrafficFlow" instead of to your session key. This is causing the URI request to return a 401 error. Try fixing the string.format and seeing if you still get this error.

    http://rbrundritt.wordpress.com

    Monday, May 26, 2014 6:27 PM
  • this is because of all the experiments I did.

    I fixed that but same error returning this weired character

    here is what I fixed

     routeRequest = RouteRequest("TrafficFlow");
    
    
    Uri routeRequest = new Uri(
                                  string.Format("http://dev.virtualearth.net/REST/V1/Imagery/Map/Road/Bellevue%20Washington?mapLayer={0}&key={1}",
                                  Query, sessionKey));

    Monday, May 26, 2014 6:54 PM
  • Ok, so, originally I thought you were trying to get imagery metadata, but the URL you are using is to get a static image. You don't use the JSON data contracts when requesting a static image. The JSON data contracts are for JSON data. Simply load the URL into an Image object, or load it in a browser window.

    http://rbrundritt.wordpress.com

    Monday, May 26, 2014 7:45 PM