1. #1
    Sencha User
    Join Date
    Jun 2011
    Posts
    131
    Answers
    1
    Vote Rating
    1
    shaoen01 is on a distinguished road

      0  

    Default Answered: Json to handle names with special character?

    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 "Gañanita", 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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,756
    Answers
    3462
    Vote Rating
    828
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


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

    http://jsonlint.com/
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,574
    Answers
    540
    Vote Rating
    311
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      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
    shaoen01 is on a distinguished road

      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
    shaoen01 is on a distinguished road

      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
    soemi is on a distinguished road

      0  

    Default [SOLVED]

    [SOLVED]


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

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi