Home  >  Article  >  Backend Development  >  解析JSON的有关问题

解析JSON的有关问题

WBOY
WBOYOriginal
2016-06-13 12:58:53816browse

解析JSON的问题


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

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


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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn