json_decode为null

问题:在Laravel项目中使用guzzle请求云帆平台开放API,返回数据通过json_decode()方法解析报错:NULL string(12) "Syntax error"
$body = $response->getBody();
 
$remainingBytes = $body->getContents();
    
$res = json_decode($tmp,true);
 
$error = json_last_error_msg();
 
var_dump($res,$error);
最后解决:

$client = new Client([
    'base_uri'      => $config['base_uri'],
    'http_errors'   => false,
]);
$client_result = $client->request('POST', $api_code,['headers' => $header, 'json' => $data]);

$original_body = (string)$client_result->getBody()->getContents();
$utf8_body     = mb_convert_encoding($original_body, 'UTF-8');
$cli           = json_decode($utf8_body, true);

 

posted @ 2021-04-21 10:52  飞翔的贺兰猪  阅读(134)  评论(0编辑  收藏  举报