Home > DeveloperSection > Forums > Decode Greek characters in JSON PHP
Brad Pitt
Brad Pitt

Total Post:61

Posted on    June-20-2013 2:55 AM


 1 Reply(s)
 2049  View(s)
Rate this:
Hi Expert,

I have an XML document that contains greek characters and works perfectly. When I convert it to JSON using PHP the greek characters are being encoded.

      {"id":"101","name":"\u0398\u0397\u039a\u0395\u03a3 \u0397\/\u03a5"}

What I do is: Write xml to a file and then read the file and convert it to JSON

      $handle = fopen("xml_cat.xml","w+");
      fwrite($handle, $xml);
      $sxml = simplexml_load_file('xml_cat.xml');
      echo json_encode($sxml);

How can I get greek characters back?

Any help on above is really appreciated.

Sumit Kesarwani

Total Post:378

Posted on    June-20-2013 6:55 AM

Hi Brad,

Any client which can properly decode the JSON format will get the original characters back. "\uXXXX" is a perfectly valid transport encoding for arbitrary characters in the JSON format. You don't need to do anything special, you just need to decode the JSON properly; something you're doing anyway when working with JSON. 

Don't want to miss updates? Please click the below button!

Follow MindStick