【发布时间】:2014-10-03 21:02:04
【问题描述】:
我正在为我的一位客户开发运输 API。我有供应商的运输 api。在以 json 格式发出 curl 请求时,json 响应未转换为 php 数组?找到下面的代码:
$params['format'] = 'json';
$params['data'] =json_encode($package_data);
$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$url = "http://test.shipping.co/push/json/?token=".$token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
$results = json_decode($result, true);
print_r($results);
这里有 2 个 print_r 函数,输出如下:
{ "cash_pickups_count": 1.0, "cod_count": 0, "success": true, “package_count”:1,“upload_wbn”:“UPL21969440”,“replacement_count”: 0,“cod_amount”:0.0,“prepaid_count”:0,“pickups_count”:0, “包裹”:[{“状态”:“成功”,“运单”:“0008110000125”, “refnum”:“8”,“client”:“demo”,“remarks”:“”,“cod_amount”: 21841.0,“付款”:“现金”}],“cash_pickups”:21841.0 }1
1
我收到 2 个输出:1
我想访问这个响应的 php 中的数组。我试过 json_decode() 但它没有正确响应。 在这里需要您的输入。提前致谢。
【问题讨论】: