0

I have two different set of json object as follows.

'{
  "eventos": [
     {"Event":"QueueParams","Queue":"755","Max":"0","Strategy":"fewestcalls","Calls":"0","Holdtime":"19","TalkTime":"491","Completed":"89","Abandoned":"4","ServiceLevel":"0","ServicelevelPerf":"0.0","Weight":"0","ActionID":"4152750549"},
     {"Event":"QueueMember","Queue":"755","Name":"PJSIP/428","Max":"","Location":"PJSIP/428","StateInterface":"PJSIP/428","Membership":"dynamic","Penalty":"0","CallsTaken":"2","LastCall":"1607350581","Status":"2","Paused":"0","ActionID":"4152750549"},
  ]
}';

$response = json_decode($response);
dd($response);

The problem is, it returns null output.

I want to get json result displayed with different objects. What changes are needed here so that I can display output of different objects ?

2
  • 3
    If this is truly all that is in your JSON, then it's invalid. The trailing comma behind the second object in the array should be removed. Commented Dec 10, 2020 at 15:57
  • Looking at your previous asked questions, if somebody answers your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. Commented Dec 10, 2020 at 16:01

2 Answers 2

1

Your JSON have a syntax error. Just remove the comma right after the last { ActionID":"4152750549"},.

It have to be like this:

'{
  "eventos": [
     {"Event":"QueueParams","Queue":"755","Max":"0","Strategy":"fewestcalls","Calls":"0","Holdtime":"19","TalkTime":"491","Completed":"89","Abandoned":"4","ServiceLevel":"0","ServicelevelPerf":"0.0","Weight":"0","ActionID":"4152750549"},
     {"Event":"QueueMember","Queue":"755","Name":"PJSIP/428","Max":"","Location":"PJSIP/428","StateInterface":"PJSIP/428","Membership":"dynamic","Penalty":"0","CallsTaken":"2","LastCall":"1607350581","Status":"2","Paused":"0","ActionID":"4152750549"}
  ]
}';

For any Json problem, run a json_last_error() right after the decode.

Sign up to request clarification or add additional context in comments.

Comments

1

For example, to show each ActionID;

<?php
    $rawJson = '{"eventos": [{"Event":"QueueParams","Queue":"755","Max":"0","Strategy":"fewestcalls","Calls":"0","Holdtime":"19","TalkTime":"491","Completed":"89","Abandoned":"4","ServiceLevel":"0","ServicelevelPerf":"0.0","Weight":"0","ActionID":"4152750549"}, {"Event":"QueueMember","Queue":"755","Name":"PJSIP/428","Max":"","Location":"PJSIP/428","StateInterface":"PJSIP/428","Membership":"dynamic","Penalty":"0","CallsTaken":"2","LastCall":"1607350581","Status":"2","Paused":"0","ActionID":"4152750549"} ] }';
    $json = json_decode($rawJson);

    $eventos = $json->eventos;

    foreach ($eventos as $event) {
        echo $event->ActionID . PHP_EOL;
    }

Note: There was an trailing comma (,) behind the last event object, I've removed it to make it valid JSON.

Try it online!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.