我需要使用php从json获取@attribute值。
我需要使用php获取toatal,surchargetotal,nightlyRateTotal,maxNightlyRate值。
如何使用php获取值?
如何使用php获得总金额335.72?
[RateInfo] => stdClass Object
(
[@rateChange] => false
[@promo] => true
[@priceBreakdown] => true
[ChargeableRateInfo] => stdClass Object
(
[@total] => 335.72
[@surchargeTotal] => 44.42
[@nightlyRateTotal] => 291.3
[@maxNightlyRate] => 145.65
[@currencyCode] => USD
[@commissionableUsdTotal] => 291.3
[@averageRate] => 145.65
[@averageBaseRate] => 171.35
)
)
答案 0 :(得分:3)
您可以将其类型转换为数组:
$array = (array)$object;
echo $array['ChargeableRateInfo']['@surchargetotal'];
您可以编码为JSON,然后再次解码为关联数组
$array = json_decode(json_encode($object), true);
echo $array['ChargeableRateInfo']['@surchargetotal'];
由于您没有提供任何其他信息,这是我最好的猜测。