Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个用 json_decode 创建的 PHP 变量。
结果的第一个字段有一个我存储在变量中的名称。
那么我如何通过存储在变量中的名称访问该字段呢?
我试过了:
$json_decoded->{$item}
但它返回 null....
$v = "b"; $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; $d = json_decode($json); echo $d->$v;
另一种方式
$v = "b"; $json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; $d = json_decode($json,true); echo $d[$v];
不使其成为变量:
$json_decoded->item