I'm fetching a JSON string from a php file, which returns valid JSON. In essence, the JSON that is returned looks like the following. I removed some data , but I left the data in place that seems to be causing the issue:
{"result": [
{
"prop0": 0000000,
"prop1": 0,
"prop1Desc": "a valid string",
"prop2": "00000000000",
"prop3": "00000000",
"prop4": "Kiliç",
"prop5": "00000000",
"prop6": "a valid string",
"prop7": 0.0,
"prop8": "a valid string",
"prop9": "a valid string",
"prop10": 0,
"prop11": 0,
"prop12": 0.0,
"prop13": 0.0,
"prop14": 0.0,
"prop15": 0.0,
"prop16": false,
"prop17": 0.0,
"prop18": 0
}
]}
When I use $.getJSON()
, the callback-function is not called, rather, the .fail()
callback is called.
I got hold of the textStatus
, errorThrown
and jqXHR.responseText
, which are the following:
textStatus
:parsererror
errorThrown
:SyntaxError: Ongeldig teken
(I guess that's the JS version of the error; fromJSON.parse()
)
Additionally, the jqXHR.responseText
:
{"result": [
{
"prop0": 0000000,
"prop1": 0,
"prop1Desc": "a valid string",
"prop2": "00000000000",
"prop3": "00000000",
"prop4": "Kili�
"prop5": "00000000",
"prop6": "a valid string",
"prop7": 0.0,
"prop8": "a valid string",
"prop9": "a valid string",
"prop10": 0,
"prop11": 0,
"prop12": 0.0,
"prop13": 0.0,
"prop14": 0.0,
"prop15": 0.0,
"prop16": false,
"prop17": 0.0,
"prop18": 0
}
]}
So I think somewhere along the process, jQuery does not like JSON-strings with accented characters. The ç
in Kiliç
seems to cause trouble, seemingly removing ",
at the end of the line as well... Any thoughts on what's going on, and on how I can solve this?
Update
I've looked into the suggestion of @LinkinTED, as the JSON seems to be valid upon inspecting the network. Upon inspection of the PHP file, I realized that it decodes UTF-8 encoded string.. But I'm not sure the following code is valid, as utf8_decode
is called upon a json-decoded string (which, in the end, is the valid json).. The PHP file contains the following code to echo the JSON result:
echo utf8_decode(json_decode( $response->opcResponse)->Response->DataResponse[0]->Data);
Removing the function utf8_decode
seems to have no effect. Furthermore, I changed the Content-type
header, which initially only statee Content-type: application/json
. I added ; charset=utf-8
, with no effect.
Old:
header('Content-type: application/json');
New:
header('Content-type: application/json; charset=utf-8');