从result-php解析结果
我如何在这个回复中获得费用的价值 我正在php应用程序中集成postman api,为此我使用了一个来自php的curl调用 这是密码从result-php解析结果,php,laravel,curl,postmates,Php,Laravel,Curl,Postmates,我如何在这个回复中获得费用的价值 我正在php应用程序中集成postman api,为此我使用了一个来自php的curl调用 这是密码 <?php class PostMates extends Controller { public function getDeliveryQuote() { $url = "https://api.postmates.com/v1/customers/cus_XX/delivery_quotes"; $una
<?php
class PostMates extends Controller {
public function getDeliveryQuote()
{
$url = "https://api.postmates.com/v1/customers/cus_XX/delivery_quotes";
$uname = "70538e7";
$pwd = "xxxx";
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded','Accept: application/json'));
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERPWD, $uname . ":" . $pwd);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_POSTFIELDS, "dropoff_address=20 McAllister St, San Francisco, CA 94102&pickup_address=101 Market St, San Francisco, CA 94105");
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
$return = curl_exec($process);
curl_close($process);
//var_dump($return);
print_r($return);
}
}
给你。您必须解析结果
$result = json_decode($result,true); //decodes JSON to associative array
echo $result['fee']; //750
或者,如果要使用对象格式
$result = json_decode($result); //decodes JSON to an object
echo $result->fee; //750
编辑
您还需要将CURLOPT_标题设置为false
这包括输出中的响应头
curl_setopt($process, CURLOPT_HEADER, false);
谢谢,但我一直在尝试获取非对象的属性,所以这是与curl verbose相比的实际$request内容。改变事情的输出——检查我的答案的另一半的编辑
curl_setopt($process, CURLOPT_HEADER, false);