Sir D
Sir D

Reputation: 2396

Convert JSON String to Array

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()?

Upvotes: 1

Views: 91

Answers (2)

Pranav C Balan
Pranav C Balan

Reputation: 115222

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));    
?>

http://php.net/json_decode

Upvotes: 1

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"

Upvotes: 6

Related Questions