Results 1 to 6 of 6

Thread: Json to handle names with special character?

  1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    131
    Answers
    1
    Vote Rating
    1
      0  

    Default Answered: Json to handle names with special character?

    Hi All,

    I am using a grid to pull out data from mysql database. I realized that names with special characters such as "Gaanita", this field will not be displayed in my grid. I suspect it is due to JSON not able to handle it when i sent over to my grid?

    I am using Firebug to debug and i see null values being passed. And when i check in my database table, the name is there. Any ideas on how to tackle this? Thanks

  2. Your description of seeing nulls makes me suspicious that the problem lies elsewhere but here's some general advice on working with non-ASCII characters.

    Try to use UTF-8 to encode the characters to bytes, UTF-8 is the default encoding for JSON:

    http://www.ietf.org/rfc/rfc4627.txt?number=4627

    Alternatively you could use \uXXXX escaping on such characters, though that may be tricky if you're using a library to do the JSON creation for you:

    http://json.org/

    If you're using such characters in the dataIndex for a grid column then it may be the JS file that is being misinterpreted rather than the JSON. Try using \uXXXX escaping in your JS file. You can also use script tag attributes and response headers to control the character encoding.

  3. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Answers
    3931
    Vote Rating
    1272
      0  

    Default

    Easy way to see if it is the JSON is to plug your JSON into:

    http://jsonlint.com/
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  4. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,790
    Answers
    583
    Vote Rating
    391
      0  

    Default

    Your description of seeing nulls makes me suspicious that the problem lies elsewhere but here's some general advice on working with non-ASCII characters.

    Try to use UTF-8 to encode the characters to bytes, UTF-8 is the default encoding for JSON:

    http://www.ietf.org/rfc/rfc4627.txt?number=4627

    Alternatively you could use \uXXXX escaping on such characters, though that may be tricky if you're using a library to do the JSON creation for you:

    http://json.org/

    If you're using such characters in the dataIndex for a grid column then it may be the JS file that is being misinterpreted rather than the JSON. Try using \uXXXX escaping in your JS file. You can also use script tag attributes and response headers to control the character encoding.

  5. #4
    Sencha User
    Join Date
    Jun 2011
    Posts
    131
    Answers
    1
    Vote Rating
    1
      0  

    Default

    Thanks for the response. It seems that maybe it might not be Json. I find that the output in my php from the database is already null when i use json_encode(). Maybe i need to escape the characters before i use json_encode()? What do you think?

  6. #5
    Sencha User
    Join Date
    Jun 2011
    Posts
    131
    Answers
    1
    Vote Rating
    1
      1  

    Default

    I managed to solve the issue with this code below in my PHP file. Thanks skirtle and all!
    Code:
    mysql_query('SET CHARACTER SET utf8');

  7. #6
    Sencha User
    Join Date
    Mar 2008
    Location
    Salatiga, Central Java, Indonesia
    Posts
    4
    Vote Rating
    0
      0  

    Default [SOLVED]

    Thank you all... I use the code and all special characters show up
    PHP Code:
    mysql_query('SET CHARACTER SET utf8'); 

Posting Permissions

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