我正在使用 cURL 腳本與 API 進行通信。我撰寫了一個腳本來通過 cURL 請求檢索資料,資料顯示如下。這只是 JSON 回應的一小部分,因為通常有多個用戶在線。唯一識別符號是 ["fromAddress"]=> string(18) "127.0.0.1:5060" 無論如何都是不變的。每次從服務器發起呼叫時,CALLID 欄位都是唯一的,這真的很痛苦!
我需要使用 JSON 回應是這樣的:
從陣列中獲取 [CALLID] # 其中 ["fromAddress"] 等于"127.0.0.1:5060" 保存到 php 變數。
我不確定下一步是什么。有人可以指出我正確的方向嗎?
謝謝!
array(35) { ["callID"]=> string(22) "U1A7B9F7T61A2BC05S2eI1" ["callType"]=> string(3) "sip" ["participantID"]=> int(2) ["started"]=> int(15551212) ["updated"]=> int(15551212) ["name"]=> string(9) "TEST CALL" ["notes"]=> string(0) "" ["toNumber"]=> string(12) " 15551313" ["fromUri"]=> string(58) "sip:[email protected]:5060;pstn-params=908481808882" ["fromAddress"]=> string(18) "127.0.0.1:5060" ["fromName"]=> string(15) "WIRELESS CALLER" ["fromNumber"]=> string(12) " 15551212" ["location"]=> string(14) "SOMEWHERE, CO, US"
uj5u.com熱心網友回復:
你從 var_dump 發布了一個結果并且不完整
通常當從回應中接收 json 時,您需要使用 json_decode 將其轉換為 php 的物件,因為回應總是回傳一個字串而不是一個物件。
$obj= json_decode($response)
然后你可以像這樣訪問資料
$obj['callID']
$obj['fromAddress']
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/368477.html
標籤:php
