本文介绍了通过PHP中的JSONArray进行Foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到此错误:
这是$ json变量的回显:[{"d":"2011-03-26","q":1,"t":1060},{"d":"2011-03-26","q":2,"t":1060},{"d":"2011-03-26","q":1,"t":1060}]
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
}
推荐答案
只是一个猜测:
您的$json
变量是一个字符串.您需要使用json_decode
将其转换为对象,以迭代该对象:
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
}
这篇关于通过PHP中的JSONArray进行Foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!