Hi,
ich hab ein encoding Problem.
Um im TinyMCE eine Linkliste zu erstellen, gibt es die Möglichkeit, eine JSON-Datei zu übergeben. Das habe ich in meinem CMS (Eigenentwicklung) gemacht und es funktionierte einige Jahre.
Jetzt gab es ein Update von TinyMCE, und nun gibt es die Fehlermeldung
Hier
https://stackoverflow.com/questions/14432165/uncaught-syntaxerror-unexpected-token-with-json-parse
habe ich was interessantes darüber gefunden:
Let's say you know it's valid JSON but your are still getting this...
In that case it's likely that there are hidden/special characters in the string from whatever source your getting them. When you paste into a validator, they are lost - but in the string they are still there. Those chars, while invisible, will break JSON.parse()
If s is your raw JSON, then clean it up with:
Ich würde nun aber gerne dieses innerhalb von PHP machen, da ich den JS-Code nicht in TinyMCE reinbekomme.
Bislang ist die Ausgabe am Ende meiner PHP-JSON-Datei dieses:
ich hab ein encoding Problem.
Um im TinyMCE eine Linkliste zu erstellen, gibt es die Möglichkeit, eine JSON-Datei zu übergeben. Das habe ich in meinem CMS (Eigenentwicklung) gemacht und es funktionierte einige Jahre.
Jetzt gab es ein Update von TinyMCE, und nun gibt es die Fehlermeldung
"Unexpected token t in JSON at position 3". Position 3 ist der erste Buchstabe der Json-Datei:
Code:
[ {title: "Articles", menu: [ {title: "Privacy Policy", value: 'm.php?sid=11'}, {title: "Legal Disclosure", value: 'm.php?sid=4'} ]}, … ]
https://stackoverflow.com/questions/14432165/uncaught-syntaxerror-unexpected-token-with-json-parse
habe ich was interessantes darüber gefunden:
Let's say you know it's valid JSON but your are still getting this...
In that case it's likely that there are hidden/special characters in the string from whatever source your getting them. When you paste into a validator, they are lost - but in the string they are still there. Those chars, while invisible, will break JSON.parse()
If s is your raw JSON, then clean it up with:
Code:
// preserve newlines, etc - use valid JSON s = s.replace(/\\n/g, "\\n") .replace(/\\'/g, "\\'") .replace(/\\"/g, '\\"') .replace(/\\&/g, "\\&") .replace(/\\r/g, "\\r") .replace(/\\t/g, "\\t") .replace(/\\b/g, "\\b") .replace(/\\f/g, "\\f"); // remove non-printable and other non-valid JSON chars s = s.replace(/[\u0000-\u0019]+/g,""); var o = JSON.parse(s);
Bislang ist die Ausgabe am Ende meiner PHP-JSON-Datei dieses:
PHP-Code:
header('Content-Type: application/json; charset=UTF-8');
echo $json;
Kann mir jemand bei der richtigen Codierung helfen?
Kommentar