2017-02-22 83 views
-1

我使用curl一個respon:此網址沒有捲曲響應

{"code":200,"message":"Success","status":"success","data":{"payment_url":"http://dev.app.jualio.com/client/v2/payments/instant/AOXBE90WZY80VKDXF7M87FGGC","timestamp":"2017-02-22 12:37:36","expiry_time":"2017-02-25 12:37:36","status":"INITIATE"},"error":null} 

如何獲得payment_url?

+2

爲什麼這個標籤的正則表達式?當然你不打算用正則表達式解析JSON? – Biffen

+0

我正在考慮使用正則表達式。但我不確定。最好的方法是不是 –

+0

解碼json響應,然後你會得到一個數組,然後提取你想要的值?簡單不是嗎? –

回答

0
$result = json_decode($response); 

if ($result) { 
    echo $result->data->payment_url; 
} 
0

試試這個:

$obj = json_decode('{"code":200,"message":"Success","status":"success","data":{"payment_url":"http://dev.app.jualio.com/client/v2/payments/instant/AOXBE90WZY80VKDXF7M87FGGC","timestamp":"2017-02-22 12:37:36","expiry_time":"2017-02-25 12:37:36","status":"INITIATE"},"error":null}', true); 
OR 
$obj = json_decode($curl_reponse, true); 

echo $obj['data']['payment_url']; 

// Output: http://dev.app.jualio.com/client/v2/payments/instant/AOXBE90WZY80VKDXF7M87FGGC 

Working Example

0
<?php 
    $data = json_decode($json, true); 
    echo $data['data']['payment_url']; 
?>