Home >Backend Development >PHP Tutorial >curl get获取到一个utf-8 json字符串,用json_decode解析说格式不对。
$ch = curl_init();//初始化curl curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HEADER, 0); $data=curl_exec($ch); print_r(json_decode($data)); echo json_last_error_msg();//提示符号错误
.....
$data=curl_exec($ch);
echo base64_encode($data);
贴出结果
PGh0bWw+DQo8aGVhZD48dGl0bGU+MzAxIE1vdmVkIFBlcm1hbmVudGx5PC90aXRsZT48L2hlYWQ+DQo8Ym9keSBiZ2NvbG9yPSJ3aGl0ZSI+DQo8Y2VudGVyPjxoMT4zMDEgTW92ZWQgUGVybWFuZW50bHk8L2gxPjwvY2VudGVyPg0KPGhyPjxjZW50ZXI+bmdpbng8L2NlbnRlcj4NCjwvYm9keT4NCjwvaHRtbD4NCg==
加上
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);