Reputation: 2840
I have a problem that drives me crazy at the moment. Via JQuery I request a JSON document from the server, which is not accepted (the error is "unexpected character"). However my JSON document seems just fine, in Firebug i.e. the JSON data is correctly detected and parsed.
If I copy the response and try to validate it via jsonlint.com it always fails on the first character ([
). If I change some characters and copy stuff around but leaving the result the same it then validates (try for example copying the contents of []
and then erase them and write them again, paste the content again and you have the same document but it now validates). Strange. So I thought it may be related to the encoding, but firefox clearly states that everything is UTF8 encoded.
Now I'm kind of clueless what do to and I hope you can help me in any way.
Here is the JSON reponse of my server:
[
{
"id": 67,
"startdate": "01.01.1970 01:00:00",
"hometeam": "EHC Muskrats",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 69,
"startdate": "01.01.1970 01:00:00",
"hometeam": "EC Mammuts",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 70,
"startdate": "01.01.1970 01:00:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "EC Mammuts"
} , {
"id": 86,
"startdate": "01.01.1970 01:00:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "EC Mammuts"
} , {
"id": 4,
"startdate": "08.10.2012 21:00:00",
"hometeam": "Wiener Teifl",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 18,
"startdate": "28.10.2012 21:00:00",
"hometeam": "EC Heizbären",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 19,
"startdate": "04.11.2012 18:00:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "Innviertel Penguins"
} , {
"id": 6,
"startdate": "15.11.2012 21:00:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "EC Heizbären"
} , {
"id": 62,
"startdate": "17.11.2012 19:30:00",
"hometeam": "EC V.U. Totonka",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 12,
"startdate": "22.11.2012 20:30:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "EHC Muskrats"
} , {
"id": 13,
"startdate": "27.11.2012 19:30:00",
"hometeam": "TÜV Cannibals",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 7,
"startdate": "02.12.2012 17:00:00",
"hometeam": "Fire Fighters jun.",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 63,
"startdate": "03.12.2012 19:00:00",
"hometeam": "",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 8,
"startdate": "09.12.2012 17:00:00",
"hometeam": "EHC Vienna Flames",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 14,
"startdate": "17.12.2012 20:15:00",
"hometeam": "EC Mammuts",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 15,
"startdate": "07.01.2013 20:15:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "EC Mammuts"
} , {
"id": 9,
"startdate": "10.01.2013 20:00:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "EHC Chiefs"
} , {
"id": 11,
"startdate": "19.01.2013 21:00:00",
"hometeam": "EC Attacki",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 16,
"startdate": "24.01.2013 20:30:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "TÜV Cannibals"
} , {
"id": 10,
"startdate": "28.01.2013 19:30:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "EC V.U. Totonka"
} , {
"id": 17,
"startdate": "30.01.2013 20:30:00",
"hometeam": "EHC Muskrats",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 65,
"startdate": "24.02.2013 21:00:00",
"hometeam": "EC Heizbären",
"awayteam": "EHC Vienna Wookies"
} , {
"id": 66,
"startdate": "28.02.2013 20:40:00",
"hometeam": "EHC Vienna Wookies",
"awayteam": "EHC Chiefs"
} , {
"id": 64,
"startdate": "08.03.2013 21:00:00",
"hometeam": "EHC Vienna Flames",
"awayteam": "EHC Vienna Wookies"
} ]
Upvotes: 2
Views: 214
Reputation: 2840
Thanks to Ravi to pointing me in the right direction. There was an invisible Character in the JSON that broke the JQuery JSON parser.
The Problem on the Server side was that 1(!) of all my Files was encoded UTF8 + BOM :-< Could have thought of that earlier. Changing the encoding solved it.
Upvotes: 0
Reputation: 15861
before ID 67, you have .
in JSON. if you remove this. it will valid. though it's not showing up in here. but if you try here you will see an extra . (dot)
before the id 67.
Check the JSON. Remove . (dot)
before the ID 67
Upvotes: 3
Reputation: 494
There is a problem with new line character at the first line of JSON. If you can't fix it on the server, try to replace these characters before parsing the JSON response in javascript.
Upvotes: 3