PHP利用json_decode解析JSON數組 

原理:

PHP中處理json數據,使用PHP的自帶解析函數json_decode,

先利用json_decode把json數組字符串,轉變為數組對象,在利用for循環獲取每個item對象,

這樣看起來,解析json是不是很輕松啊


<?php 

    $postArray ='[{"data":{"hello":"json在線解析工具"},"type":"1234","date":"2016-3-20 19:28:23","user":"276632","time_stamp":1458473303}, {"data":{"hello":"world"},"type":"1234","date":"2016-3-20 19:28:23","user":"2776632","time_stamp":1458473303}]';
     
    
    $de_json = json_decode($postArray,TRUE);
      $count_json = count($de_json);
        for ($i = 0; $i < $count_json; $i  )
           {
                //echo var_dump($de_json);
 
                  $dt_record = $de_json[$i]['date'];
                   $data_type = $de_json[$i]['type'];
                  $imei = $de_json[$i]['user'];
                  $message = json_encode($de_json[$i]['data']);

                }

?>


原文鏈接:PHP利用json_decode解析JSON數組