{
"data": [
{
"caption": "www.bollywoodtune.com",
"type": "link",
"created_ti开发者_如何学Gome": "2011-01-17T07:23:02+0000",
"updated_time": "2011-01-17T07:23:02+0000"
},
...
]
}
here is the json form, how to make a foreach? When I use
foreach ($data[0] as $result) {
...
}
it show Fatal error: Cannot use object of type stdClass as array in line foreach ($data[0] as $result)
Thanks.
When you use json_decode
, make sure that you pass true
to the second operator.
For example,
$data = json_decode($json, true);
Normally, objects converted using json_decode
will be stored as PHP objects which can't be iterated over. Passing true
as the second argument makes json_decode
convert objects to associative arrays instead.
you need to do this:
$data = json_decode($data, true);
foreach($data as $d)
{
//stmts here
}
for more information about the parameters visit php manual for json
decode the json data
$data= json_decode($data,true);
foreach ($data as $v)
{
}
精彩评论