我无法从json_decode数组中获取所需的标题数据,得分,我已经尝试了stackoverflow中已经讨论过的所有方法。任何人都可以帮助我..
$myKEY = "xyz";
$url_req= 'google api request here';
$results= checkPageSpeed($url_req_d);
$googleapi = json_decode($results,true);
Google api在var_dump($ googleapi)时发送这样的数据,我需要从数组中获取标题和得分值。请回复建议的代码以提取标题和分数值,即“xyz”和“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
}, .........
答案 0 :(得分:1)
$googleapi['title']
和$googleapi['ruleGroups']['SPEED']['score']
应该可以解决问题。检查documentation以获取有关如何从多维数组访问元素的更多信息。