php 返回数据 json 的是 utf-8 ,接口需要返回中文 要求是 GBK, json_encode 只支持 utf-8
public function toJson($content){
if(is_string($content) ) {
return urlencode($content);
}elseif(is_array($content)){
foreach ( $content as $key => $val ) {
if($key == 'Status') {
$value = $val;
}else {
$value = $this->toJson($val);
}
$content[$key] =$value;
}
return urldecode(json_encode($content));
}elseif(is_object($content)) {
$vars = get_object_vars($content);
foreach($vars as $key=>$val) {
$content[$key] = $this->toJson($val);
}
return urldecode(json_encode($content));
} else{
return urldecode(json_encode($content));
}
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
直接json_encode就可以了,因为encode会直接把中文转码成字符发送出去了,也就不存在需要考虑太多的格式