I am pulling JSON data from a URL and attempting to display a list of just the display names.
In a way, this would be very easy too loop through if I knew that X amount of results would return each time. However, the results returned will vary from 0 to 50+.
I have done plenty of searches that all say "just use json_decode"... not so much the case.
I have the following JSON:
{
"ACK": "SUCCESS",
"ERROR": null,
"AGENT": {
"has_results": 1,
"agents": [
{
"display_name": "Alex",
"time_in_state": "5214",
"state": "Aux",
"callstakentoday": null,
"callsouttoday": null,
"agntpriority": null,
"skill_num": "76"
},
{
"display_name": "Bill",
"time_in_state": "6312",
"state": "Aux",
"callstakentoday": null,
"callsouttoday": null,
"agntpriority": null,
"skill_num": "76"
},
{
"display_name": "Carrie",
"time_in_state": "5982",
"state": "Aux",
"callstakentoday": null,
"callsouttoday": null,
"agntpriority": null,
"skill_num": "76"
},
{
"display_name": "David",
"time_in_state": "4226",
"state": "Aux",
"callstakentoday": null,
"callsouttoday": null,
"agntpriority": null,
"skill_num": "76"
}
]
},
"SKILL": {
"has_results": 1,
"num_skills": 1,
"skills": [
{
"display_name": "Phone Skills",
"skill_num": "76",
"callsinqueue": "0",
"callstoday": "9",
"abandtoday": "0",
"lwt": "0",
"ewt": "0",
"servicelvl": "100",
"avgspeedans": "6",
"talktime": "289"
}
]
},
"TIME": 1383766541
}
From the examples and documentation I have read, the following code has been created:
<?php
$url="http://myjsonurl.local";
$json = file_get_contents($url);
//echo $json;
$json = json_decode($json);
foreach($json as $item->display_name)
{
echo $item->agents->display_name;
}
?>
My end goal is to have a list of only names which I can then display in an alternate webpage.
So my question is... how do I read this page and format the data nicely (perhaps an array I can just print?) so I can utilize it in the future?