In php5, I was provided with two functions, json_encode and json_decode, which can realize the mutual conversion between json and arrays, but they are not well supported in Chinese. Here is a processed function that supports the mutual conversion between Chinese arrays and json.
The code is as follows
代码如下 |
复制代码 |
/**
* json 生成,分析 支持中文
*/
class Json_Helper {
/**
* 生成json
*/
public static function encode($str){
$json = json_encode($str);
//linux
return preg_replace("#u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '1'))", $json);
//windows
//return preg_replace("#u([0-9a-f]{4})#ie", "iconv('UCS-2LE', 'UTF-8', pack('H4', '1'))", $json);
}
/**
* 分析json
*/
public static function decode($str) {
return json_decode($str);
}
}
?>
|
|
Copy code |
|
/**
* json generation, analysis supports Chinese
*/
class Json_Helper {
/**
* Generate json
*/
public static function encode($str){
$json = json_encode($str);
//linux
return preg_replace("#u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '1'))", $json);
//windows
//return preg_replace("#u([0-9a-f]{4})#ie", "iconv('UCS-2LE', 'UTF-8', pack('H4', '1')) ", $json);
}
/**
* Analyze json
*/
public static function decode($str) {
return json_decode($str);
}
}
?>
http://www.bkjia.com/PHPjc/632779.htmlwww.bkjia.com
trueTechArticle provides me with two functions in php5, json_encode and json_decode can realize the mutual conversion between json and array, but The support for Chinese is not good. Here is a processed array that supports Chinese...