Invalid JSON response - It's not invalid..
Invalid JSON response - It's not invalid..

Hi there,
I got an error about invalid json.. I checked it like 100 times, it's definitly not invalid. I found a character right before my json starts, but it makes no sense, there's no whitespace or anything in the code.
If this will help: http://debug.datatables.net/iyevus
There is all you need about the json response and so on..
Thanks in advance.
This discussion has been closed.
Answers
It definitely is invalid :-). Run it through JSONLint or similar to confirm.
The issue is the multi-line string:
That is not valid JSON. You need to check how that JSON is being generated and update it to handle the multi-lines correctly.
Allan
Hi Alan,
thank you for answering. But I cannot figure out how this new-line gets inserted.
Here you can see the JSON Response directly: http://www.metin2reloaded.net/SoNiice/request.php?module=main&action=highscore&datatables=true&draw=1&columns[0][data]=0&columns[0][name]=&columns[0][searchable]=true&columns[0][orderable]=true&columns[0][search][value]=&columns[0][search][regex]=false&columns[1][data]=1&columns[1][name]=&columns[1][searchable]=true&columns[1][orderable]=false&columns[1][search][value]=&columns[1][search][regex]=false&columns[2][data]=2&columns[2][name]=&columns[2][searchable]=true&columns[2][orderable]=false&columns[2][search][value]=&columns[2][search][regex]=false&columns[3][data]=3&columns[3][name]=&columns[3][searchable]=true&columns[3][orderable]=false&columns[3][search][value]=&columns[3][search][regex]=false&columns[4][data]=4&columns[4][name]=&columns[4][searchable]=true&columns[4][orderable]=false&columns[4][search][value]=&columns[4][search][regex]=false&columns[5][data]=5&columns[5][name]=&columns[5][searchable]=true&columns[5][orderable]=false&columns[5][search][value]=&columns[5][search][regex]=false&order[0][column]=0&order[0][dir]=asc&start=0&length=10&search[value]=&search[regex]=false&_=1439216393466
There is no new-line, but when I debug, I'll see the new lines. There is no code inside tho.
```$aPlayers = explode('~', file_get_contents('cache/player_ranking.txt', FILE_USE_INCLUDE_PATH));
$lCount = count($aPlayers);
$aOut = array();
I just tried to write down the json by my own, so I didn't use json_encode now. There is still atleast one line-break.
Just a guess: byte order mark in your text file?
https://duckduckgo.com/?q=bom+byte+json
Ooo - if I open the debug trace direct from the database I can see the following:
I think tangerine is absolutely spot on. The BOM is causing the issue.
Nice one!
Allan
Thank you very much, I don't know how that happened.. But somehow all my files changed to UTF8...
Have a nice day!