doucuoyan0426 2017-03-21 09:46
浏览 36
已采纳

无法通过PHP中的json_decode从Google API获取所需数据

I am unable to fetch desired data of title, score from the json_decode array, I have tried all the ways which are already discussed in stackoverflow. Can anyone help me..

$myKEY = "xyz";
$url_req= 'google api request here';
$results= checkPageSpeed($url_req_d);
$googleapi = json_decode($results,true); 

Google api send the data like this when var_dump($googleapi) and I need to fetch title and score values from the array. Please reply suggested code to extract title and score values i.e "xyz" and "73"

{
 "kind": "pagespeedonline#result",
 "id": "www xyz com/",
 "responseCode": 200,
 "title": "xyz",
 "ruleGroups": {
  "SPEED": {
   "score": 73
  }
 },
 "pageStats": {
  "numberResources": 67,
  "numberHosts": 15,
  "totalRequestBytes": "9354",
  "numberStaticResources": 48,
  "htmlResponseBytes": "129210",
  "textResponseBytes": "5647",
  "cssResponseBytes": "142839",
  "imageResponseBytes": "411466",
  "javascriptResponseBytes": "635453",
  "otherResponseBytes": "94639",
  "numberJsResources": 17,
  "numberCssResources": 6
 },  .........
  • 写回答

1条回答 默认 最新

  • dpg98445 2017-03-21 09:50
    关注

    $googleapi['title'] and $googleapi['ruleGroups']['SPEED']['score'] should do the trick. Check the documentation for more information on how you can access elements from multidimensional arrays.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题