Php 获取JSON字符串中嵌套数组的最简单方法

Php 获取JSON字符串中嵌套数组的最简单方法,php,json,Php,Json,我是php新手。也许这是个愚蠢的问题。但是获取所有市场最新价格的最简单方法是什么?使用json\u decode函数将json字符串转换为数组并相应地遍历数组 $json_string = 'http://pubapi.cryptsy.com/api.php?method=marketdatav2'; $jsondata = file_get_contents($json_string); $jsondata=file\u get\u contents($json\u string); $a

我是php新手。也许这是个愚蠢的问题。但是获取所有市场最新价格的最简单方法是什么?

使用
json\u decode
函数将json字符串转换为数组并相应地遍历数组

$json_string = 'http://pubapi.cryptsy.com/api.php?method=marketdatav2';

$jsondata = file_get_contents($json_string);
$jsondata=file\u get\u contents($json\u string);
$array=json_decode($jsondata,true);
foreach($lprice形式的数组['return']['markets']{
$latest_price[$lprice['label']]=$lprice['lasttradeprice'];
}
回声“;
打印(最新价格);
回声“;
试试看


你的json是什么样子的,如果你发布它,查看和建议会很有帮助。可以在url中看到json,但这是一个相当大的问题。你知道如何使用方法吗?方法:getmarkets输入:n/a输出:活动市场的数组标签-此市场的名称主要货币代码主要货币代码example@user1761818我不知道你到底在问什么。
 $jsondata = file_get_contents($json_string);
 $array = json_decode($jsondata,true);
 foreach($array['return']['markets'] as $lprice) {
  $latest_price[$lprice['label']] = $lprice['lasttradeprice'];
}
 echo "<pre>";
 print_r($latest_price);
 echo "<pre>";
$decoded = json_decode($jsondata);
$latestprices = array();
foreach($decoded['return']['markets'] as $val) {
    $latestprices[$val['label']] = $val['lasttradeprice'];
}