开发者

How do I extract a value from this json_decode?

I have got this result using json decode from an api call. but I dont know ho开发者_Python百科w to extract "VALUE" from this result..

$obj=json_decode($json_string);
print_r($obj);

stdClass Object ( [status] => OK [data] => stdClass Object ( [trends] => stdClass Object ( [rank] => Array ( [0] => stdClass Object ( [date] => 201011 [value] => 7196 ) ) ) [trends_low_sample] => [query_cost] => 1 [trends_frequency] => monthly ) ) 

I need only "7196" from this result. how do I do this??


Ah! Based on your updated code you're tring to get the value from PHP not Javascript? Personally I use json_decode($json_string,true); to get an associative array (json_decode), if you do that it should be accessible as:

echo $obj["data"]["trends"]["rank"][0]["value"];

As an object it's accessible as:

echo $obj->data->trends->rank[0]->value;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜