views:

190

answers:

2

Hi,

I use Zend Framework and I have problem with JSON and UTF-8.

Output

\u00c3\u00ad\u00c4\u008d
íÄ

I use...

JavaScript (jQuery)

  • contentType : "application/json; charset=utf-8",
  • dataType : "json"

Zend Framework

  • $view->setEncoding('UTF-8');
  • $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
  • header('Content-Type: application/json; charset=utf-8');
  • utf8_encode();
  • Zend_Json::encode

Database

  • resources.db.params.charset = "utf8"
  • resources.db.params.driver_options.1002 = "SET NAMES utf8"
  • resources.db.isDefaultTableAdapter = true

Collation

utf8_unicode_ci

Type

MyISAM

Server

  • PHP Version 5.2.6

What did I do wrong? Thank you for your reply!

+1  A: 

utf8_encode();

If you've got UTF-8 strings from your database and UTF-8 strings from your browser, then you don't need to utf8_encode any more. You've already got UTF-8 strings; calling this function again will just give you the UTF-8 representation of what you'd get if you read UTF-8 bytes as ISO-8859-1 by mistake.

Pass your untouched UTF-8 strings straight to the JSON encoder.

bobince
Great! It works! Thank you so much!
Randy Mayer
A: 

I think this question is some how related to yours my problem was when encoding some [ Arabic , Hebrew or Chinese as you might see ] turns out that unicode notation understood by javascript/ecmascript like what did you see

I hope that explain to you in details

tawfekov