1

Possible Duplicate:
jQuery won't parse my JSON from AJAX query

So I have parsed and JSON stringified a 'free to use' KML file (which is basically just XML for Google maps) so that I can loop through every countries borders. Now my issue is when I do attempt to go through the JSON array it gives me "syntax error".

My current code is:

$.ajax({
    type: "GET",
    url: "./doc.json",
    dataType: "json",
    success: function (json) {
        var len = json.length;
        for (i = 0; i <= len; i++) {
            //Do stuff
        }
    }
});

For some reason this is giving me this error:

syntax error @ file:///C:/Users/Toms/Documents/WorldWar/doc.json:1

I have the file on pastebin (warning its rather large) http://pastebin.com/0CN9EWja and I have attempted to use 'JSON Lint' to verify it however the file is too large and crashes my browser before being able to verify it. I can see there is a few null arrays thrown in there randomly but I wouldn't have thought that this would stop it being valid JSON.

Community
  • 1
  • 1
Tom C
  • 744
  • 6
  • 23

2 Answers2

4

You're going out of bounds.

//   --------v
for (i = 0; i < len; i++) {
McGarnagle
  • 96,448
  • 30
  • 213
  • 255
  • Ah thanks, I always seem to mess that one up. However this still unfortunately doesn't fix the issue of it telling me the JSON is invalid. (Although it does help the issue of the obvious bug finding I would have had to find later on down the line) – Tom C Jun 24 '12 at 21:28
  • @gdoron Hardly a question asked many of times, the issue I specifically was having wasn't caused by the answer provided. It was simply because I was running on a local server which didn't send Mime types correctly. I literally hadn't seen the question asked here before and the only time I saw it was after - hence why I posted another answer linking back to another question (somewhat similar to mine). Really if something is telling you there's a syntax error in your JSON you are not immediately going to think its an issue with jQuery so you wont search for that when looking for answers. – Tom C Jun 25 '12 at 14:45
  • 1
    @TomC, My comment had nothing to do with this question-answer. It just was the last post of am not i am, and I wanted to leave him a comment. I'm sorry, there's just no other way. I deleted my comment. Again, I'm sorry. – gdoron is supporting Monica Jun 25 '12 at 14:52
3

Found the issue @ jQuery won't parse my JSON from AJAX query

Thanks to those who attempted to help. My specific issue was fixed by "Josh" witht he beforeSend code.

Community
  • 1
  • 1
Tom C
  • 744
  • 6
  • 23