This article describes the JSON Chinese processing solution for PHP. Share to everyone for your reference, specific as follows:
JSON is a widely used format for passing strings, which is easier to understand and easier to manipulate than XML, with two functions, Json_encode () and Json_deconde () in PHP. However, JSON's support for Chinese is not very good, and if you use Json_encode () to handle an array, if there is a Chinese in the arrays, it will be treated as white space.
One way to solve Chinese is to convert Chinese to another encoding format before using Json_encode (), and then decoding the JSON strings. There is another way to get the solution in the new version of PHP, shown in the code below.
The following is a code example
<?php
Header ("Content-type:text/html;charset=utf-8");
$arrayName = Array (' City ' => ' Guangdong ', ' goods ' => ' cookies ');
$arr = Json_encode ($arrayName);
echo $arr. " </br> ";
Var_dump (Json_decode ($arr));
echo "</br>";
Echo UrlDecode (Json_encode (Ch_json ($arrayName)). " </br> ";
/* Need PHP version above 5.4
echo json_encode ($arrayName, json_unescaped_unicode);
*/
function Ch_json ($arr) {
if (Is_array ($arr)) {
foreach ($arr as $key => $value) {
$arr [ UrlEncode ($key)] = Ch_json ($value);
}
} else{return
UrlEncode ($arr);
}
return $arr;
>
PS: Here again for you to recommend a few more practical JSON online tools for your reference to use:
Online JSON code inspection, inspection, landscaping, formatting tools:
Http://tools.jb51.net/code/json
JSON Online formatting tool:
Http://tools.jb51.net/code/jsonformat
Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson
JSON code online Format/beautify/compress/edit/Convert tools:
Http://tools.jb51.net/code/jsoncodeformat
C Language Style/html/css/json code formatting landscaping Tools:
Http://tools.jb51.net/code/ccode_html_css_json
For more information about PHP interested readers can view the site topics: "PHP JSON format data Operation tips Summary", "PHP for XML file Operation skills Summary", "PHP basic Grammar Introductory Course", "PHP Array" Operation Techniques Encyclopedia, "PHP string ( String) Usage summary, "Getting Started with Php+mysql database operations" and "Summary of common PHP database Operations Tips"
I hope this article will help you with the PHP program design.