今天调试代码的时候发现json_encode()报错问题如下描述:
问题代码:
$requestData = json_encode(
array(
'wechat_group_name' => $wechat_group_name,
'text_message' =>$text_message,//该值是中文一个拼接字符串
)
);
能后报错PHP Warning: json_encode(): Invalid UTF-8 sequence in argument in /home/leyangjun/myshop/leyangjun.php on line 188
原因:变量中包含一些非utf-8字符,需要统一下字符编码
解决:把需要json_encode编码的值转下编码格式:
$requestData = json_encode(
array(
'wechat_group_name' => $wechat_group_name,
'text_message' => mb_convert_encoding($text_message,'UTF-8','UTF-8'),
)
);
能后OK解决
作者:乐杨俊