I'm getting this error:
Warning: Invalid argument supplied for foreach() in [page].php on line 49
This is an echo of the $json variable:
[{"d":"2011-03-26","q":1,"t":1060},{"d":"2011-03-26","q":2,"t":1060},{"d":"2011-03-26","q":1,"t":1060}]
And I'm trying to iterate through like so:
foreach($json as $obj) { // <--THIS IS LINE 49
// Stuff
}
Just a guess:
Your $json
variable is a string. You'll need to convert it to an object using json_decode
to iterate through the object:
$json_obj = json_decode( $json );
foreach( $json_obj as $obj )
{
//stuff
}
you have to decode the json before you can iterate it.
The JSON-String itself is meaningless to foreach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With