A
A
Alexander2016-10-02 16:51:34
PHP
Alexander, 2016-10-02 16:51:34

How to parse JSON response in a loop?

There is JSON:

Array
(
    [0] => stdClass Object
        (
            [call_id] => 147532********************200
            [sip] => 100
            [callstart] => 2016-10-01 16:30:36
            [clid] => Operator (100) 
            [destination] => 8***************
            [disposition] => answered
            [seconds] => 3
            [is_recorded] => true
            [pbx_call_id] => out_************************************
        )

    [1] => stdClass Object
        (
            [call_id] => 14753****************3
            [sip] => 100
            [callstart] => 2016-10-01 16:31:06
            [clid] => Operator (100) 
            [destination] => 89**************
            [disposition] => answered
            [seconds] => 2
            [is_recorded] => true
            [pbx_call_id] => out_**********************************
        )

    [2] => stdClass Object
        (

And so on, 20 objects.
How can I display them in a loop in order in a readable form?
I try like this:
$answerObject = json_decode($answer);
  foreach ($answerObject as $key => $value) {
    echo $answerObject->call_id;
  }

But somehow empty on the page :( Help! :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2016-10-02
@SmoKE_xD

Semyon Semenych:

$answerObject = json_decode($answer);
  foreach ($answerObject as $value) {
    echo $value->call_id;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question