如何显示此字符串中的键值?

时间:2014-04-11 05:40:04

标签: php json

这是我的JSON数据

{"subtotal":{"amount":"403.95","currency":"USD"},"fees":[{"coinbase":{"amount":"4.04","currency":"USD"}},{"bank":{"amount":"0.15","currency":"USD"}}],"total":{"amount":"408.14","currency":"USD"},"amount":"408.14","currency":"USD"}

我只需要显示"金额"关键,我试图解析json ..我是否正确地解决了这个问题?

2 个答案:

答案 0 :(得分:1)

这样做

<?php
$str='{"subtotal":{"amount":"403.95","currency":"USD"},"fees":[{"coinbase":{"amount":"4.04","currency":"USD"}},{"bank":{"amount":"0.15","currency":"USD"}}],"total":{"amount":"408.14","currency":"USD"},"amount":"408.14","currency":"USD"}';
$arr=json_decode($str,true);

echo $arr['subtotal']['amount'];

答案 1 :(得分:1)

试试这个

$jsondata = '{"subtotal":{"amount":"403.95","currency":"USD"},"fees":[{"coinbase":{"amount":"4.04","currency":"USD"}},{"bank":{"amount":"0.15","currency":"USD"}}],"total":{"amount":"408.14","currency":"USD"},"amount":"408.14","currency":"USD"}';$jsondata1 = json_decode($jsondata);echo $jsondata1->amount;echo $jsondata1->subtotal->amount;