I have this JSON string
{"ticker":{"high":736.45099,"low":681,"avg":708.725495,"vol":13038780.63684,"vol_cur":18382.55965,"last":726,"buy":726,"sell":724.5,"updated":1388242741,"server_time":1388242743}}
How can i get the "last" parameter after doing json_decode()?
Shankar Narayana Damodaran
68.6k43 gold badges102 silver badges129 bronze badges
asked Dec 28, 2013 at 15:19
Sir D
2,4162 gold badges19 silver badges22 bronze badges
2 Answers 2
Do like this
<?php
$json='{"ticker":{"high":736.45099,"low":681,"avg":708.725495,"vol":13038780.63684,"vol_cur":18382.55965,"last":726,"buy":726,"sell":724.5,"updated":1388242741,"server_time":1388242743}}';
$json_arr=json_decode($json,true);
echo $json_arr['ticker']['server_time'];//"prints" 1388242743 which is the last param "server time"
answered Dec 28, 2013 at 15:21
Shankar Narayana Damodaran
68.6k43 gold badges102 silver badges129 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
Powerslave
Actually, the op asked about getting the parameter called
"last". Other than that, this answer is the right one.Amal
I too thought in a similar way and hence my comment. +1 anyway. :)
Use json_decode with parameters json string and TRUE.When TRUE, returned objects will be converted into associative arrays.
<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json, true));
?>
answered Dec 28, 2013 at 15:22
Pranav C Balan
115k25 gold badges173 silver badges195 bronze badges
Comments
lang-php
$jsonArray = json_decode('...', true) echo $jsonArray['ticker']['last'];