Rumah > php教程 > php手册 > PHP 解析JSON数组

PHP 解析JSON数组

WBOY
Lepaskan: 2016-07-09 09:09:17
asal
871 orang telah melayarinya
<span style="color: #000000;">php 

    </span><span style="color: #800080;">$postArray</span> ='[{"data":{"hello":"world"},"type":"1234","date":"2012-10-30 17:6:9","user":"000000000000000","time_stamp":1351587969902}, {"data":{"hello":"world"},"type":"1234","date":"2012-10-30 17:12:53","user":"000000000000000","time_stamp":1351588373519}]'<span style="color: #000000;">;
     
    
    </span><span style="color: #800080;">$de_json</span> = json_decode(<span style="color: #800080;">$postArray</span>,<span style="color: #0000ff;">TRUE</span><span style="color: #000000;">);
      </span><span style="color: #800080;">$count_json</span> = <span style="color: #008080;">count</span>(<span style="color: #800080;">$de_json</span><span style="color: #000000;">);
        </span><span style="color: #0000ff;">for</span> (<span style="color: #800080;">$i</span> = 0; <span style="color: #800080;">$i</span> $count_json; <span style="color: #800080;">$i</span>++<span style="color: #000000;">)
           {
                </span><span style="color: #008000;">//</span><span style="color: #008000;">echo var_dump($de_json);</span>
 
                  <span style="color: #800080;">$dt_record</span> = <span style="color: #800080;">$de_json</span>[<span style="color: #800080;">$i</span>]['date'<span style="color: #000000;">];
                   </span><span style="color: #800080;">$data_type</span> = <span style="color: #800080;">$de_json</span>[<span style="color: #800080;">$i</span>]['type'<span style="color: #000000;">];
                  </span><span style="color: #800080;">$imei</span> = <span style="color: #800080;">$de_json</span>[<span style="color: #800080;">$i</span>]['user'<span style="color: #000000;">];
                  </span><span style="color: #800080;">$message</span> = json_encode(<span style="color: #800080;">$de_json</span>[<span style="color: #800080;">$i</span>]['data'<span style="color: #000000;">]);

                }

</span>?>
Salin selepas log masuk
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan