Solved

How to use/display arrayed results from json decode?  Example needed

Posted on 2015-01-20
2
83 Views
Last Modified: 2015-01-21
Ok, I've got json data and decoded it with json_decode:

      $data = json_decode($json_info,true);

when I do this:

      var_dump($data);

I get results like this:

   http://shoutkey.com/expulsion

Now that I've got that array.... I'm not sure how to use it.

Can you give me an example of code that will display the first six results for the ChannelName, DisplayTime and ProgramTitle, after they are parsed, so I have:

ChannelName value 1, DisplayTime value 1, ProgramTitle value 1
ChannelName value 2, DisplayTime value 2, ProgramTitle value 2
ChannelName value 3, DisplayTime value 3, ProgramTitle value 3
ChannelName value 4, DisplayTime value 4, ProgramTitle value 4
ChannelName value 5, DisplayTime value 5, ProgramTitle value 5

Big ask I know, I would really appreciate the help!
0
Comment
Question by:St_Aug_Beach_Bum
2 Comments
 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
ID: 40562350
$tvShows = json_decode($json_info,true);

for ($i = 0; $i < 5) {
    echo 'ChannelName is '. $tvShows[$i]["ChannelName"]. 
    ', DisplayTime is ' .$tvShows[$i]["DisplayTime"]. 
    ', ProgramTitle is ' .$tvShows[$i]["ProgramTitle"] . '<br />';
    }

Open in new window

I think this should work, although I did not test it.
  Ask questions if you need more information.
0
 

Author Closing Comment

by:St_Aug_Beach_Bum
ID: 40562690
Got it!

I had to change the 'for' to this:

for ($i = 0; $i <= 5; $i++) {   //based on example at php.net

but you got me going in the right direction here - thank you very much!

Chris
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now