首頁 >後端開發 >php教程 > 解析JSON的有关问题

解析JSON的有关问题

WBOY
WBOY原創
2016-06-13 12:58:53965瀏覽

解析JSON的问题

<br />
{<br />
	"code":"A0001",<br />
	"serverTime":12345,<br />
	"data":[<br />
		{"epgId":"1103226854","endTime":"12000"},<br />
		{"epgId":"1103226855","endTime":"12300"},<br />
		{"epgId":"1103226857","endTime":"12350"},<br />
		{"epgId":"1103226858","endTime":"12356"}<br />
	]<br />
}<br />

假设有这一段JSON数据,需要获得其中 第一个endTime值大于serverTime值(12345)那一项中epgId的值(12350)


------解决方案--------------------
$s='{<br />
    "code":"A0001",<br />
    "serverTime":12345,<br />
    "data":[<br />
        {"epgId":"1103226854","endTime":"12000"},<br />
        {"epgId":"1103226855","endTime":"12300"},<br />
        {"epgId":"1103226857","endTime":"12350"},<br />
        {"epgId":"1103226858","endTime":"12356"}<br />
    ]<br />
}';<br />
$arr=json_decode($s,true);<br />
foreach($arr['data'] as $v){<br />
     if($v['endTime']>$arr['serverTime']){ <br />
	     echo $v['epgId'];<br />
		 break;<br />
	 }	   <br />
}

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn