本文介绍了在JSON中获取特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何通过以下方式使用PHP访问第三个"value":
I'm wondering how do i access the 3rd "value" using PHP in the following:
"data": [ { "id": "-", "name": "-", "period": "-", "values": [ { "value": 0, "end_time": "2011-10-08T07:00:00+0000" }, { "value": 0, "end_time": "2011-10-09T07:00:00+0000" }, { "value": 0, "end_time": "2011-10-10T07:00:00+0000" } ]就目前而言,我正在尝试做以下事情:
As for now I'm trying to do something with:
$results = json_decode(curl_exec ($curl));但是我被困住了,因为"values"里面有3个"value",说实在的我很困惑.
But then I'm stuck because there are 3 "value" inside of "values" and to tell you the truth I'm pretty confused..
推荐答案此代码仅供您理解,您可以从中得到更好的主意.
this code is just for your understanding you can get the better idea from this.
<?php $json = '[{"id": "-","name": "-","period": "-","values": [{"value": 0,"end_time": "2011-10-08T07:00:00+0000"},{"value": 0,"end_time": "2011-10-09T07:00:00+0000"},{"value": 0,"end_time": "2011-10-10T07:00:00+0000"}]}]'; $jasondata =json_decode($json,true); echo $jasondata[0]['values'][2]['value']; exit; echo "<pre>"; print_r($jasondata); exit; ?>更多推荐
在JSON中获取特定值
发布评论