duanping3587
2010-12-22 20:07
浏览 97

如何从此json_decode中提取值?

I have got this result using json decode from an api call. but I dont know how 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??

图片转代码服务由CSDN问答提供 功能建议

我使用api调用的json解码得到了这个结果。 但我不知道如何从这个结果中提取“VALUE”..

  $ obj = json_decode($ json_string); 
print_r($ obj); 
 
stdClass Object  ([status] => OK [data] => stdClass对象([trends] => stdClass对象([rank] =>数组([0] => stdClass对象([date] => 201011  [value] => 7196)))[trends_low_sample] => [query_cost] => 1 [trends_frequency] =>每月))
   
 
 

I 从这个结果只需要“7196”。 我该怎么办?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doufan3958 2010-12-22 20:11
    已采纳

    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;
    
    点赞 打赏 评论

相关推荐 更多相似问题