Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I query a specific field from JSON response?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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:5551212@127.0.0.1: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"

>Solution :

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']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading