场景:
$x = json_decode( $x );
foreach ( $x as $item )
{
$info[] = $item; //ERROR
}
Run Code Online (Sandbox Code Playgroud)
我正在循环使用数据馈送来获取数据.我想在循环中将项添加到stdClass对象.我该怎么办?我对stdobj不太熟悉.
如果您希望json_decode返回一个数组,您可以执行以下操作:
$x = json_decode( $x, true ); // returns associative array instead of object
$info = (object) $x;
Run Code Online (Sandbox Code Playgroud)
可在此处找到更多信息和示例.