在JSON中获取特定值

编程入门 行业动态 更新时间:2024-10-07 16:20:06
本文介绍了在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中获取特定值

本文发布于:2023-11-26 21:41:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635297.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定值   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!