从页面获得的字符串json_decode失败 40
我有一个页面输出{"status":"success","num":"4"},用curl读取回来后想用json_decode()解析成数组,一直不成功,代码如下:$rs=...
我有一个页面输出{"status":"success","num":"4"},用curl读取回来后想用json_decode()解析成数组,一直不成功,代码如下:
$rs=catchByCurl("http://localhost/baicai/api/goods.php");
$rs=preg_replace('/\t|\n|\r/is','',$rs);
echo $rs;
echo '</br>';
print_r(json_decode($rs,true));
echo '</br>';
echo mb_detect_encoding($rs);
echo '</br>';
print_r(json_decode('{"status":"success","num":"4"}',true));
echo '</br>';
$R=file_get_contents('http://localhost/baicai/api/goods.php');
$R=preg_replace('/\t/i','',$R);
print_r(json_decode($R,true));
以上代码输出:
{"status":"success","num":"4"}
{"status":"success","num":"4"}
UTF-8
Array
(
[status] => success
[num] => 4
)
{"status":"success","num":"4"}
求解。
问题出在文件编码上utf8+的问题 展开
$rs=catchByCurl("http://localhost/baicai/api/goods.php");
$rs=preg_replace('/\t|\n|\r/is','',$rs);
echo $rs;
echo '</br>';
print_r(json_decode($rs,true));
echo '</br>';
echo mb_detect_encoding($rs);
echo '</br>';
print_r(json_decode('{"status":"success","num":"4"}',true));
echo '</br>';
$R=file_get_contents('http://localhost/baicai/api/goods.php');
$R=preg_replace('/\t/i','',$R);
print_r(json_decode($R,true));
以上代码输出:
{"status":"success","num":"4"}
{"status":"success","num":"4"}
UTF-8
Array
(
[status] => success
[num] => 4
)
{"status":"success","num":"4"}
求解。
问题出在文件编码上utf8+的问题 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询