使用php从JSON获取@attributes
我需要使用php从json获取@attribute值 我需要使用php获取toatal、surchargetotal、NightLyrateTall、maxNightlyRate值 如何使用php获取值使用php从JSON获取@attributes,php,json,Php,Json,我需要使用php从json获取@attribute值 我需要使用php获取toatal、surchargetotal、NightLyrateTall、maxNightlyRate值 如何使用php获取值 [RateInfo] => stdClass Object ( [@rat
[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
)
)
如何使用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
)
)
您可以将其类型转换为数组:
$array=(array)$object;
echo$array['ChargeableRateInfo']['@surchargetotal'];
您可以编码为JSON,然后作为关联数组再次解码
$array=json\u decode(json\u encode($object),true);
echo$array['ChargeableRateInfo']['@surchargetotal'];
由于您没有提供其他信息,这是我最好的猜测。您可以将其键入数组:
$array=(array)$object;
echo$array['ChargeableRateInfo']['@surchargetotal'];
您可以编码为JSON,然后作为关联数组再次解码
$array=json\u decode(json\u encode($object),true);
echo$array['ChargeableRateInfo']['@surchargetotal'];
由于您没有提供其他信息,这是我最好的猜测。是否显示JSON?这是一部分内容的转储。您当前的实现有什么问题?发布更多的代码、您尝试过的内容以及您当前的代码有什么问题如何使用phpMaybe显示JSON获取总量335.72?这是部分内容的转储。您当前的实现有什么问题?发布更多的代码、您尝试过的内容以及您当前的代码有什么问题如何使用php$array=(array)$object获得总量335.72;echo$array['ChargeableRateInfo']['@surchargetotal'];这对我很有帮助。现在我可以接受echo$array['ChargeableRateInfo']['@surchargetotal'];谢谢,单击左侧“向下投票”按钮下方的“接受答案”图标;)要使用php从json获取@attribute值,需要在{}之间封装key。类似于:
RateInfo->ChargeableRateInfo->{“@surchargeTotal”}
$array=(array)$object;echo$array['ChargeableRateInfo']['@surchargetotal'];这对我很有帮助。现在我可以接受echo$array['ChargeableRateInfo']['@surchargetotal'];谢谢,单击左侧“向下投票”按钮下方的“接受答案”图标;)要使用php从json获取@attribute值,需要在{}之间封装key。这样:RateInfo->ChargeableRateInfo->{“@surchargeTotal”}