使用
json_decode()
先解码JSON。然后通过它的
statisticalvalues
commoditycodes
具有相同的数组索引
商品代码
数组。请记住,实际值位于名为
key_0
.
<?php
$json = '{"name":"myjsonstring","statisticalvalues":[{"key_0":"677876"},{"key_0":"0"}],"commoditycodes":[{"key_0":"90001000"},{"key_0":"80001000"}]}';
$obj = json_decode($json,false);
foreach ($obj->statisticalvalues as $key => $value) {
echo $value->key_0 . "\t\t" . $obj->commoditycodes[$key]->key_0 . "\n";
}
?>
在您的情况下,可能是:
<?php
$obj = $request->input();
foreach ($obj["statisticalvalues"] as $key => $value) {
echo $value["key_0"] . "\t\t" . $obj["commoditycodes"][$key]["key_0"] . "\n";
}
?>