PHP スクリプトを変更して、JSON オブジェクトを受け取り、その特定の JSON オブジェクトを操作できるようにしようとしています。forループを使用して、JSONから変換されたオブジェクトの配列(別名「もの」)を循環しようとするまで、すべて正常に機能します。
ここで何が間違っていますか:
$json = '{
"foo": "hi",
"bar": "bye"
"stuff": [{"widget":"dd"},{"thing":"cc"},{"wcha":"dd"}]
}';
$arr = json_decode($json, true);
$foo = $arr['foo']; //works fine
$bar = $arr['bar']; //works fine
//old way that worked:
//$stuff = array("widget" => "dd", "thing" => "cc", "wcha" => "dd");
//new way that does not work:
$stuff = $arr['stuff'];
...
//This is where the problem is:
foreach ($stuff as $key => $value){...
for ループの問題は、$key が整数 (実際の値ではない) であり、$value が「配列」という単語 (実際の値ではない) であることです。