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']);

                }

?>