在JSON中获取特定值 [英] Get a specific value in JSON

查看:70
本文介绍了在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中获取特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆