2017-03-22 67 views
2

我想從執行cUrl發佈請求後得到的響應中得到來自json數組的「標記」的值。在print_r($response);之後它打印出所有這些。但我只想使用json字符串和一個特定的值。從cURL獲取沒有標題的json響應的值

這是我的迴應。我不希望所有這些在響應之前

HTTP/1.1 200 OK<br/> 
Content-Type: application/json<br/> 
Content-Length: 312<br/> 
Connection: keep-alive<br/> 
Vary: Accept-Encoding<br/> 
Status: 200 OK<br/> 
Cache-Control: max-age=0, private, must-revalidate<br/> 
Date: Wed, 22 Mar 2017 12:52:25 GMT<br/> 
Strict-Transport-Security: max-age=31536000<br/> 
X-Request-Id: 9418df03bea4e4884522b703d0eec504<br/> 
X-UA-Compatible: IE=Edge,chrome=1<br/> 
ETag: "dd4de4d3a6e4e499d6a034ce784d2d76"<br/> 
X-Runtime: 0.633173<br/> 
X-Content-Type-Options: nosniff<br/> 
X-Rack-Cache: invalidate, pass<br/> 
X-Powered-By: Phusion Passenger 5.0.28<br/> 
Server: nginx/1.10.0 + Phusion Passenger 5.0.28 

{"response_code":"00","response_text":"Mobile wallet payment request has been issued.","description":"You will receive a bill prompt shortly on your number 0546653444 with invoice no. 201562656, kindly complete it.","transaction_id":"DTV408402","token":"8268dfffa46a16b0665a76","mobile_invoice_no":"201562656"} 
+2

什麼是你使用,你怎麼想去做 ??給一些想法。 –

+0

'curl_setopt($ ch,CURLOPT_HEADER,0);' – AbraCadaver

+0

@AbraCadaver,非常感謝喲,將它添加到答案中,以便我可以將您的答案作爲正確答案投票。 –

回答

0

你需要告訴你不想頭捲曲:

curl_setopt($ch, CURLOPT_HEADER, 0); 
-2

你可以在這個響應中使用php的explode()函數。或者你可以調整你的curl請求,不要返回你的請求頭。

$split=explode("\n\n",$response); 
$array=json_decode($split[1],true); 
var_dump($array); 

如果這不起作用,修改爆炸功能分割上爲 「\ r \ n \ r \ n」,而不是 「\ n \ n」;