php代码
/** * 中文编码JSON * @param $data * @return string */ function encode_json($data){ if(version_compare('5.4',PHP_VERSION,'<')){ //5.4以上 return json_encode($data,JSON_UNESCAPED_UNICODE); }else{ return urldecode(json_encode(url_encode($data))); } }
/** * URL编码(可迭代数组) * @param $str * @return array|string */ function url_encode($str) { if(is_array($str)) { foreach($str as $key=>$value) { $str[urlencode($key)] = url_encode($value); } } else { $str = urlencode($str); } return $str; }