Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将JSON字符串转换为数组_Php_Arrays_Json_Function - Fatal编程技术网

Php 将JSON字符串转换为数组

Php 将JSON字符串转换为数组,php,arrays,json,function,Php,Arrays,Json,Function,我有这个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\u decode()之后,如何获取“last”参数 <?php $json='{"ticke

我有这个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\u decode()
之后,如何获取“last”参数

<?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"
你喜欢这样做吗

<?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"

使用json\u decode和参数json stringTRUE。如果为TRUE,返回的对象将转换为关联数组

<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';     
var_dump(json_decode($json, true));    
?>


使用参数json字符串TRUEjson\u decode。如果为TRUE,返回的对象将转换为关联数组

<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';     
var_dump(json_decode($json, true));    
?>


$jsonArray=json_decode(“…”,true)echo$jsonArray['ticker']['last']
$jsonArray=json_decode('…',true)echo$jsonArray['ticker']['last']
实际上,op询问如何获取名为
“last”
的参数。除此之外,这个答案是正确的。我也以类似的方式思考,因此+1.:)实际上,op要求获取名为
“last”
的参数。除此之外,这个答案是正确的。我也以类似的方式思考,因此+1.:)