Unexpected token : from a URL with extension . json

Asked

Viewed 33 times

0

When trying to get a JSON through the URL: http://www.cidades.ibge.gov.br/gmap/shapes/35/MU_M13_3550308_1000.json

I get a status 200 with the error:

Uncaught SyntaxError: Unexpected token :

Using AJAX as follows:

$(document).ready(function($) {
  $.ajax({
    type: "GET",
    url: "http://www.cidades.ibge.gov.br/gmap/shapes/35/MU_M13_3550308_1000.json",
    dataType: "jsonp",
    success: function(data) {
      console.log(data);
    },
    error: function(xhr, ajaxOptions, thrownError) {
      console.log(xhr.status);
      console.log(thrownError);
    }
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

What is the cause of the error?

1 answer

1


The content of URL provided does not return a valid JSON. That’s why you’re having this error.

Apparently, in the specific case of your problem, looks like the quotes are missing from the keys to the items. What I would do is create an endpoint on an intermediate server that downloads the original file, treats it and returns the fixed file.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.