View Full Version : Character Encoding in JSON
Hi,
I have a PHP script in the background that returns JSON encoded strings for my grid. I'm using the pear class Services_JSON (http://mike.teczno.com/JSON/JSON.phps) which encodes my UTF8 special chars (german umlauts) in this way: Schr\u00c3\u00b6der :s
In my grid all special chars are broken - all my script files are utf8, the server responses are utf8, the db collation.. quite everything.
I have a selfmade proxy class that retrieves the data from the server. Is it possible to decode the masked chars with javascript back to
neongrau
5 Apr 2007, 1:48 AM
check in firebug what content-type the server sends to your browser:
should be s.th. like
Content-Type application/json; charset=utf-8
or
Content-Type text/html; charset=UTF-8
in the "Headers / Response Headers" tab
the json response is part of an XML document: Content-Type text/xml; charset="utf-8"
edit:
ok, problem solved. someone entered dump into my database and I believed everything would be ok there...sorry
Meister_R
11 May 2007, 4:40 AM
same Problem here;
in contrast that the whole project is ISO-8859-1 coded :-(
so is there an easy way to get my '
neongrau
11 May 2007, 5:23 AM
welcome to encoding hell,
basically "ISO-8859-1" has no support for german "umlauts".
your system is automatically falling back to "ISO-8859-15" or "windows-1252" which can have umlauts.
so you can try to force everything to one of those encodings (especially the content-type for XHRs), or if possible: try to do everything everywhere in UTF-8 (i know that's not always possible but it's the best solution i can think of).
Hi,
I solved the problem for german umlauts with this PHP function:
[CODE]function json_umlaut($var){
if(is_array($var)){
foreach(array_keys($var) as $key){
$var[$key]=json_umlaut($var[$key]);
}
return $var;
}else{
$var=preg_replace("/
u39kun
28 Mar 2008, 2:46 PM
I had a problem rendering european characters within GridPanel.
I solved this issue by doing this (we use Java):
response.setCharacterEncoding("UTF-8");
davidrolli
6 May 2009, 7:05 AM
for PHP it's
require_once ('JSON/JSON.php'); // PEAR library 'Services_JSON', http://pear.php.net/package/Services_JSON
...
$json = new Services_JSON();
echo utf8_encode($json->encode($a_result));
Levona
18 Apr 2010, 2:50 AM
What about right to left text encoding (like Hebrew/Arabic)?
The JSON seems to encode a sentence in right to left languages backwards (For example encoding "Hello world" (In Hebrew) returns "world Hello"). How can I prevent this from happening?
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.