I'm working on a cURL script to communicate with an API. I wrote a script to retrieve the data with a cURL request and the data is displaying as follows. This is just one chunk of the JSON response as there are usually multiple users online. The unique identifier is ["fromAddress"]=> string(18) "127.0.0.1:5060" which is constant no matter what. The CALLID field is unique every time a call is initiated from the server which makes it a real pain!
What I need to with the JSON Response is this:
Get [CALLID] from array# where ["fromAddress"] equals"127.0.0.1:5060" Save to a php variable.
I'm not sure what the next step is. Can someone please point me in the right direction?
Thanks!
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"
CodePudding user response:
you posted a result from var_dump and is not complete
usually when receive json from a response you need to convert it to php's object using json_decode since response always return a string instead an object.
$obj= json_decode($response)
then you can access the data like thia
$obj['callID']
$obj['fromAddress']