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

无法通过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 *. 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
 },  .........

我无法获取所需的标题数据,从json_decode数组得分,我已经尝试了所有方法 已在*中讨论过。 任何人都可以帮助我.. p>

  $ myKEY =“xyz”; 
 $ url_req ='google api request here'; 
 $ results = checkPageSpeed($ url_req_d);  
 $ googleapi = json_decode($ results,true);  
  code>  pre> 
 
 

Google api在var_dump($ googleapi)时发送这样的数据,我需要从数组中获取标题和得分值。 请回复建议的代码以提取标题和分数值,即“xyz”和“73” p>

  {
“kind”:“pagespeedonline#results”,
“id”  :“www xyz com /”,
“”responseCode“:200,
”title“:”xyz“,
”ruleGroups“:{
”SPEED“:{
”得分“: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 
},......... 
  code>  pre> 
  div>

$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.