Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

utf 8 - Cyrillic characters in PHP's json_encode

I'm trying to encode Cyrillic UTF-8 array to JSON string using php's function json_encode. The sample code looks like this:

<?php
  $arr = array(
     'едно' => 'първи',
     'две' => 'втори'
  );
  $str = json_encode($arr);
  echo $str;
?>

It works fine but the result of the script is represented as:

{"u0435u0434u043du043e":"u043fu044au0440u0432u0438","u0434u0432u0435":"u0432u0442u043eu0440u0438"}

which makes 6 characters for each Cyrillic character. Is there a way to get the original characters for key/value pairs instead of encoded ones?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Can't you use JSON_UNESCAPED_UNICODE constant here?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...