从URL-php搜索JSON对象
我有一个url返回:从URL-php搜索JSON对象,php,json,Php,Json,我有一个url返回: [{"account":"123","address":"abc","category":"receive","amount":12,"confirmations":10,"tx":"6f8fa99a88c266ce403e0108f926adc02288f89be30adc298485961ac332a314"}, {"account":"123","address":"def","category":"send","amount":-5,"fee":-0.01,"con
[{"account":"123","address":"abc","category":"receive","amount":12,"confirmations":10,"tx":"6f8fa99a88c266ce403e0108f926adc02288f89be30adc298485961ac332a314"},
{"account":"123","address":"def","category":"send","amount":-5,"fee":-0.01,"confirmations":8,"tx":"6f8fa99a88c266ce403e0108f926adc02288f89be30adc298485961ac332a314"},
{"account":"123","address":"ghi","category":"receive","amount":23.59,"confirmations":5,"tx":"8b20ed5bf4a4d299bad42fd49b8aabf6456366b235288f34f79d9f2321cd11c9"}]
我尝试了在SO找到的各种选项,但只能显示所有对象/值或使用下面的代码显示值。但无法搜索所有对象,只能从一个特定对象检索数据
所有对象都有一些完全相同的值。我想循环查看特定“地址”的所有对象,如果找到,则显示“金额、确认、发送”值
如何在php中检索和使用
$array = json_decode($string, true);
foreach ( $array as $k=>$item ) {
if ( $item['address']=='def' ) {
/* Display other values for this record */
echo 'Amount: ' . $item['amount'];
/* etc. */
};
};
$array = json_decode($string, true);
foreach ( $array as $k=>$item ) {
if ( $item['address']=='def' ) {
/* Display other values for this record */
echo 'Amount: ' . $item['amount'];
/* etc. */
};
};