PHP读取sqlserver数据使用json_decode没有返回值

$sql = "SELECT a FROM `table_a`"; 

首先检测搜索得到的字符串的编码类型 

mb_detect_encoding($row['a'], array("ASCII",'UTF-8',"GB2312","GBK",'BIG5'));

如果得到的编码类型不是"UTF-8",则无法使用json_decode进行编码。

当编码为"ASCII",转换成"UTF-8":

iconv('ASCII','UTF-8',$row['a']);

当编码为"GB2312"/"GBK",转换成"UTF-8":

urlencode(iconv('ASCII','UTF-8',$row['a']));

再使用json_encode

你可能感兴趣的:(PHP)