json不支持中文写入的问题解决
写两个函数,使其支持中文:
function arrayRecursive(&$array, $function, $apply_to_keys_also = false) { foreach ($array as $key => $value) { if (is_array($value)) { arrayRecursive($array[$key], $function, $apply_to_keys_also); } else { $array[$key] = $function($value); } if ($apply_to_keys_also && is_string($key)) { $new_key = $function($key); if ($new_key != $key) { $array[$new_key] = $array[$key]; unset($array[$key]); } } } }
function JSON($array) { arrayRecursive($array, ‘urlencode‘, true); $json = json_encode($array); return urldecode($json); }
调用示例如下
$guanggao_list=array( 0=>array( "iid"=>21341872612, "goods_name"=>"新款热销男装男士韩版修身裤休闲裤男裤 修身版休闲男装长裤子", "goods_list_img"=>"http://img01.taobaocdn.com/bao/uploaded/i1/13692019653157760/T1RedmXvBdXXXXXXXX_!!0-item_pic.jpg_310x310.jpg", "url"=>"http://item.taobao.com/item.htm?spm=a230r.1.10.17.G7a5Tc&id=18937863889", "shichangjia"=>"359.00", "taobaojia"=>"199.00", "daoqi"=>1362105283, "wangwang"=>"芭菲雨" ), 1=>array( "iid"=>21341872612, "goods_name"=>"新款热销男装男士韩版修身裤休闲裤男裤 修身版休闲男装长裤子", "goods_list_img"=>"http://img03.taobaocdn.com/imgextra/i3/745475881/T20n1JXmVbXXXXXXXX_!!745475881.jpg_460x460.jpg", "url"=>"http://item.taobao.com/item.htm?spm=a230r.1.10.17.G7a5Tc&id=18937863889", "shichangjia"=>"359.00", "taobaojia"=>"199.00", "daoqi"=>1372105283, "wangwang"=>"小鱼儿" ) ); $str=JSON($guanggao_list); print_r($str);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。