转换json

时间:2012-11-08 07:54:09

标签: php json

大家好,我正努力在我的网站上显示天气更新。 因为我正在发送一些代码,这些代码正在向我返回一些类似下面的内容

stdClass Object
(
    [data] => stdClass Object
        (
            [current_condition] => Array
                (
                    [0] => stdClass Object
                        (
                            [temp_C] => 26
                            [temp_F] => 79
                        )



                )
        )
)

我想获取temp_C,它位于[o] => stdClass对象之下 为此,我使用了这样的语句

//$returning is variable have all the json in it
$celcius = $returning->data->current_condition->0->temp_c;

请指导我如何获得temp_C ,,,我目前正在使用php。 感谢所有人

1 个答案:

答案 0 :(得分:1)

current_condition是一个数组

$celcius = $returning->data->current_condition[0]->temp_c;