0

I have an array in PHP which has values in Thai language. when I use json_encode to pass values in javascript only json_decode does not gives the output ,returns blank.

print_r ($myarray) this returns output in Thai language.

json_encode($myarray) returns output '\u0e23'. How to convert it to Thai language output .

Hrudaya Palwe
  • 103
  • 1
  • 4
  • 11
  • Add complete code. Your JSON object and how you're encoding/decoding it – Tushar Jul 10 '15 at 06:41
  • are the contents encoded? http://php.net/manual/en/function.utf8-encode.php – Swaraj Giri Jul 10 '15 at 06:41
  • Can you check the encoding of one of the strings in Thai. I had a similar problem before with Chinese language. – Neal Jul 10 '15 at 06:42
  • 1
    `\u0e23` is a Thai character, represented as a Unicode escape. Try this: `echo json_decode('"\u0e23"');` – Amadan Jul 10 '15 at 06:52
  • @Amadan yes it is working i was missing double quotes. I have to send an object .`json_decode` gives warning it accepts only string not an array so any idea ? how to send an object – Hrudaya Palwe Jul 10 '15 at 06:59
  • JSON is a string, always. What kind of object are you trying to send to `json_decode`? It would be much better if you posted a snippet of your code that demonstrates your error. – Amadan Jul 10 '15 at 07:00
  • [link]http://jsfiddle.net/2sL9mLyq/ this kind of object – Hrudaya Palwe Jul 10 '15 at 07:15
  • That is not valid PHP. How are you passing that to `json_decode`, if not as a string?!? Again, post the snippet of code that you are executing, because this makes no sense. If I do `print_r(json_decode('...what you posted...'));`, I am getting a perfectly fine PHP structure, with Thai strings no less. – Amadan Jul 10 '15 at 07:46
  • my basic need is i have to display thai characters in javascript on phonegap app , so I was using `json_encode` in php to receive data in my app to display those thai characters but it is displaying like this `/u0e23` in my app and on php side it is displaying like this `\u0e23`, i just tried `json_decode` to get the desired output but it did not work what you tried . – Hrudaya Palwe Jul 10 '15 at 08:15

1 Answers1

1

The function itself modifies the codification the string.

Use this as a second parameter: JSON_UNESCAPED_UNICODE

 json_encode( $myarray, JSON_UNESCAPED_UNICODE );

Check out the constants and choose the best for you.

Community
  • 1
  • 1
SpongePablo
  • 870
  • 10
  • 24