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

PHP 解析JSON数组

WBOY
WBOYoriginal
2016-07-09 09:09:17876parcourir
<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>?>
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn