Results 1 to 9 of 9

Thread: Character Encoding in JSON

  1. #1
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    germany
    Posts
    52

    Default 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

    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

  2. #2
    Ext JS Premium Member neongrau's Avatar
    Join Date
    Mar 2007
    Posts
    282

    Default

    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

  3. #3
    Ext JS Premium Member
    Join Date
    Mar 2007
    Location
    germany
    Posts
    52

    Default

    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

  4. #4

    Default

    same Problem here;

    in contrast that the whole project is ISO-8859-1 coded :-(

    so is there an easy way to get my '

  5. #5
    Ext JS Premium Member neongrau's Avatar
    Join Date
    Mar 2007
    Posts
    282

    Default

    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).

  6. #6
    Ext User
    Join Date
    Mar 2008
    Location
    Germany
    Posts
    2

    Default

    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("/

  7. #7

    Default solved by setting encoding to UTF-8 for JSON output

    I had a problem rendering european characters within GridPanel.
    I solved this issue by doing this (we use Java):

    response.setCharacterEncoding("UTF-8");

  8. #8
    Sencha User
    Join Date
    Feb 2008
    Location
    Bottmingen, Switzerland
    Posts
    6

    Default

    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));

  9. #9

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •