我得到了这种JSON数据,如何在PHP中逐个提取?

时间:2017-11-10 06:02:59

标签: php json

Json

data ={
"2":
  {
    "routtype":"Transactional", 
    "credit":40000,
    "validity":"4616",
    "availablecredit":"39457"
  }
}

如何逐个将此数据提取到变量中

1 个答案:

答案 0 :(得分:2)

假设$ json_array为你的数组。

$data = json_decode($json_array); 
foreach($data as $dt){
    $routtype = $dt->routtype;
    $credit = $dt->credit;
    $validity = $dt->validity;
    $availablecredit = $dt->availablecredit;
    echo $routtype;
    echo $credit;
    echo $validity;
    echo $availablecredit;
}