duanping3587 2010-12-22 20:07
浏览 149
已采纳

如何从此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??

  • 写回答

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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划