如何在PHP中拆分这种类型的字符串并获得特定的值 [重复] 。

问题描述 投票:-1回答:1

我有一个这样的字符串

{"Account":{"Currency":"SGD","CreditLimit":0.0000,"Balance":1649.5700},"Status":36,"Code":891,"Message":"Success"}-

我需要平衡的值。

我试过这样。

$string = '{"Account":{"Currency":"SGD","CreditLimit":0.0000,"Balance":1649.5700},"Status":1,"Code":1,"Message":"Success"}-';
$withCharacter = strstr($string, 'Balance":');
echo substr($withCharacter, 1); 

也试过使用explode,但没有成功。

php
1个回答
2
投票

这似乎是一个有效的JSON,为什么不呢?json_decode 并找出数值。

$i = json_decode('{"Account":{"Currency":"SGD","CreditLimit":0.0000,"Balance":1649.5700},"Status":36,"Code":891,"Message":"Success"}');
echo $i->Account->Balance;
© www.soinside.com 2019 - 2024. All rights reserved.