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.

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

报告相同问题?