Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6778
| Message-ID | <20380527.UJKVNz4fzF@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-08-12 23:30 +0200 |
| Subject | Re: json_decode problem |
| Newsgroups | comp.lang.php |
| References | <slrnk2avb8.be8.houghi@penne.houghi> <k055v2$62k$1@dont-email.me> <3488766.5KQix4pcSt@PointedEars.de> <k08klq$d1v$1@dont-email.me> |
| Followup-To | comp.lang.php |
Followups directed to: comp.lang.php
Gregor Kofler wrote:
> Am 2012-08-12 13:44, Thomas 'PointedEars' Lahn meinte:
>> Gregor Kofler wrote:
>>> Am 2012-08-10 23:30, houghi meinte:
>>>> <?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
>>>> }
>>>> ?>
>>>>
>>>> I do get the above part right, but I am lost on how to do the rest. I
>>>> assume I must do some other foreach.
>>>
>>> foreach($p->lines as $l) {
>>> echo $l->stage;
>>>
>>> if(isset($l->quote)) {
>>> echo $l->quote;
>>> }
>>>
>>> if(isset($l->chars) {
>>> foreach($l->chars as $c) {
>>> echo $c->char;
>>> echo $c->nconst;
>>> }
>>> }
>>>
>>> ....
>>> }
>>
>> FYI: isset() should not be used with properties, because it fails with
>> protected or private properties that have getters:
>
> Thanks, for pointing out potential problems, though the returned object
> is a stdClass instance and all properties are public.
Apparently you have missed (and snipped) the part of my answer that
discusses when and when not to use isset() with json_decode() return values,
and why.
> (Anyway, I prefer to treat JSON responses as associative arrays.)
The second argument passed to json_decode() being TRUE. ACK. However, that
does not help with the isset() issue.
PointedEars
--
Sometimes, what you learn is wrong. If those wrong ideas are close to the
root of the knowledge tree you build on a particular subject, pruning the
bad branches can sometimes cause the whole tree to collapse.
-- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
json_decode problem houghi <houghi@houghi.org.invalid> - 2012-08-10 23:30 +0200
Re: json_decode problem Gregor Kofler <usenet@gregorkofler.com> - 2012-08-11 10:43 +0200
Re: json_decode problem houghi <houghi@houghi.org.invalid> - 2012-08-11 13:09 +0200
Re: json_decode problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-12 13:44 +0200
Re: json_decode problem Luuk <luuk@invalid.lan> - 2012-08-12 15:28 +0200
Re: json_decode problem Luuk <luuk@invalid.lan> - 2012-08-12 15:32 +0200
Re: json_decode problem Gregor Kofler <usenet@gregorkofler.com> - 2012-08-12 18:12 +0200
Re: json_decode problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-12 23:30 +0200
Re: json_decode problem Curtis Dyer <dyer85@gmail.com> - 2012-08-20 10:41 +0000
Re: json_decode problem Jerry Stuckle <jstucklex@attglobal.net> - 2012-08-20 07:30 -0400
Re: json_decode problem Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-08-20 16:45 +0200
Re: json_decode problem houghi <houghi@houghi.org.invalid> - 2012-08-11 10:54 +0200
Re: json_decode problem Luuk <luuk@invalid.lan> - 2012-08-11 11:05 +0200
Re: json_decode problem houghi <houghi@houghi.org.invalid> - 2012-08-11 13:11 +0200
csiph-web