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

PHP 解析JSON数组

WBOY
WBOYOriginal
2016-07-09 09:09:17876Durchsuche
<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>?>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn