简体   繁体   English

如何从此json_decode中提取值?

[英]How do I extract a value from this json_decode?

I have got this result using json decode from an api call. 我从api调用中使用json解码获得了此结果。 but I dont know how to extract "VALUE" from this result.. 但我不知道如何从此结果中提取“ VALUE”。

$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. 从这个结果中我只需要“ 7196”。 how do I do this?? 我该怎么做呢??

Ah! 啊! Based on your updated code you're tring to get the value from PHP not Javascript? 根据您更新的代码,您正试图从PHP而不是Javascript获得价值? Personally I use json_decode($json_string,true); 我个人使用json_decode($json_string,true); to get an associative array ( json_decode ), if you do that it should be accessible as: 获取关联数组( json_decode ),如果这样做,则可以通过以下方式访问它:

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

As an object it's accessible as: 作为对象,可以通过以下方式访问:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM