FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » json_decode problem
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: json_decode problem [message #178841 is a reply to message #178839] Sat, 11 August 2012 09:05 Go to previous messageGo to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma:
Senior Member
On 11-08-2012 10:54, houghi wrote:
> houghi wrote:
>> I am stuck with json_decode. I have a json file
>> http://houghi.org/Fun/imdb.json
>> <?php
>> $json = file_get_contents("imdb.json");
>> $result = json_decode($json);
>> foreach($result->data->quotes as $p)
>> {
>> $qconst = $p->qconst;
>> echo "quotenumber = $qconst<br>";
>> //Some foreach here?
>> //No idea what to put here
>> }
>> ?>
>
> As always one finds the answer shortly after posting, regardless how
> many hours you were looking for the solution. (30-40 over a weeks
> period)
>
> The file I use is http://houghi.org/Fun/imdb.json
>
> <?php
> $json = file_get_contents("imdb.json");
> $result = json_decode($json);
> foreach($result->data->quotes as $p)
> {
> $qconst = $p->qconst;
> print "quote=$qconst<br>\n";
> $qconst = $p->lines;
> foreach ($qconst as $q)
> {
> $quote = $q->quote;
> $stage = $q->stage;
> if ($stage != "") { $stage = '<i>['.$stage.']</i> ';}
> $chars = $q->chars;
> foreach ($q->chars as $r)
> {
> $char = $r->char." ";
> $nconst = $r->nconst." ";
> }
> print $char.$nconst.$stage.$quote."<br>\n";
> }
> print "<hr>\n";
> }
> ?>
>
> It seems obvious now. Anybody an idea on how to improve it? I myself
> will re-write the output to put the data it in a database (for personal
> use).
>
> houghi
>

use isset() to check if a quote of stage exists....
(see post from Gregor)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: PEAR Auth package woes
Next Topic: redirect on zend
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 30 23:44:59 GMT 2024

Total time taken to generate the page: 0.03966 seconds