PHP JSON - 只取一个值[关闭]

I'm new to using PHP & JSON, and I'm basically trying to retrieve just the latest values using PHP (for the date 29-MAY-2013). Is there a set function for this?

{"Latest":[
{
     "Date":"29-May-2013",
     "1":"33","2":"3"
},

{
     "Date":"30-May-2013",
     "1":"10","2":"31"
}

Your json seems to be invalid, maybe missing some brackets. If it's your json:

{"Latest":[
{
     "Date":"29-May-2013",
     "1":"33","2":"3"
},

{
     "Date":"30-May-2013",
     "1":"10","2":"31"
}
]}

Then to grab the first date PHP code will be something like this:

    $json = '{"Latest":[
{
     "Date":"29-May-2013",
     "1":"33","2":"3"
},

{
     "Date":"30-May-2013",
     "1":"10","2":"31"
}
]}';

     $array = json_decode($json, TRUE);
     print_r($array['Latest'][0]);

I believe this is what you are looking for:

http://php.net/manual/en/function.json-decode.php

You can just create your own function only selecting the required data (in your case the first line)

example of json_decode:

$json = '{"foo-bar": 12345}';

$obj = json_decode($json);
print $obj->{'foo-bar'}; // 12345

?>