您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)php程序如何遍歷json數(shù)據(jù),小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
1、json_decode是php5.2.0之后新增的一個(gè)PHP內(nèi)置函數(shù),其作用是對(duì)JSON格式的字符串進(jìn)行編碼。
2、接受JSON格式的字符串并且把它轉(zhuǎn)換為PHP變量。
當(dāng)該參數(shù)$assoc為T(mén)RUE時(shí),將返回array,否則返回object。
語(yǔ)法規(guī)則:
json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
實(shí)例
<?php $str = '{ "10924": { "id": "10924", "title": "天津", "streamline_title": "狗不理", "unit": "點(diǎn)", "goods_type": "168", "goods_type_title": "包子" }, "10923": { "id": "10923", "title": "北京", "streamline_title": "王府井", "unit": "點(diǎn)", "goods_type": "104", "goods_type_title": "吃貨天堂" }, "11982": { "id": "11982", "title": "南京", "streamline_title": "夫子廟", "unit": "點(diǎn)", "goods_type": "351", "goods_type_title": "燈會(huì)" } }'; foreach (json_decode($str) as $v) { echo "{$v->id} {$v->title}"; //其他的一樣的 }
關(guān)于“php程序如何遍歷json數(shù)據(jù)”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。