0

i decoded the json data using php json_decode here is my output with print_r

stdClass Object ( 
[uv] => stdClass Object ( 
[current] => stdClass Object ( 
[class_name] => delta-positive 
[display] => 668 [value] => 668 ) 
[yoy_perc] => stdClass Object ( 
         [class_name] => delta-negative 
         [display] => -21.23% 
         [value] => -21.23 ) 
[mom_perc] => stdClass Object ( 
         [class_name] => delta-negative 
         [display] => -8.87% [value] => -8.87 ) 
[yoy] => stdClass Object ( 
         [class_name] => delta-negative 
         [display] => -180 [value] => -180 ) 
[mom] => stdClass Object ( 
         [class_name] => delta-negative 
         [display] => -65 
         [value] => -65 ) ) 
[page_title] => example.com 668 UVs for December 2012 | Compete 
[rank] => stdClass Object ( 
        [current] => stdClass Object ( 
           [class_name] => delta-positive 
             [display] => 1,398,481 
            [value] => 1398481 ) [yoy] => stdClass Object ( [class_name] => delta-negative [display] => -187,667 [value] => -187667 ) [last_month] => stdClass Object ( [class_name] => delta-positive [display] => 1,246,200 [value] => 1246200 ) [mom] => stdClass Object ( [class_name] => delta-negative [display] => -152,281 [value] => -152281 ) [last_year] => stdClass Object ( [class_name] => delta-positive [display] => 1,210,814 [value] => 1210814 ) ) ) 

i need to get

[display] => 668 [value] => 668 )

668

of this i tried using foreach but no luck. anyone know how to do that using php an efficient way i mean without a loop thank you

4

5 回答 5

0

Try this:

object->uv->current->display;
object->uv->current->value;

or use json_decode PHP function.

于 2013-01-19T19:00:23.003 回答
0
$obj->uv->current->value
于 2013-01-19T19:01:33.613 回答
0

尝试使用json_decode()第二个参数集以使其输出数组而不是对象结构。

`$outputArray = json_decode($inputString, true);

这将允许您使用foreach().

于 2013-01-19T19:02:44.960 回答
0

如果您对对象不满意,您可以简单地将“true”放在 json_decode() 的第二个参数中。

json_decode($jsondata, true);

因此,您可以将它们作为数组访问。

于 2013-01-19T19:02:54.553 回答
0

使用 json_decode($json, true) 获取关联数组。

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

于 2013-01-19T19:03:34.317 回答