-1

I Have a string like this

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

I need the value of Balance.

I tried like this.

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

Tried to use explode also but no luck.

Daniel_Knights
  • 7,940
  • 4
  • 21
  • 49
satish k
  • 37
  • 7

1 Answers1

2

This seems like a valid JSON, why not json_decode and find the value:

$i = json_decode('{"Account":{"Currency":"SGD","CreditLimit":0.0000,"Balance":1649.5700},"Status":36,"Code":891,"Message":"Success"}');
echo $i->Account->Balance;
Ron
  • 5,900
  • 2
  • 20
  • 30