所以我有一些相对简单的JSON我尝试使用PHP显示,我陷入困境,我想也许我没有使用解码或正确编码。也许我只是忽略了一些东西。PHP JSON编码或解码?
这里的JSON ...
{
"numFound": 43640,
"start": 0,
"maxScore": 0.7847167,
"docs": [],
"facets": {}
}
这里是我的PHP ...
<?php
$json_returned = file_get_contents("URL_OF_JSON_SOURCE");
$decoded_results = json_decode($array, true);
{
foreach($decoded_results as $results){
echo "Number Found:".$results['numFound'].";
echo "Start:".$results['start'].";
}
}
?>
我主要只是想获得 “numFound”, “开始” 和 “maxScore”显示。感谢您的帮助,甚至花时间阅读这篇文章。
其中'$ array'?也许你的意思是'json_decode($ json_returned,true)'? –
为什么你的'foreach'包裹在括号里? – Machavity
以下是源代码JSON https://api.data.gov/gsa/fbopen/v0/opps?q=technology&data_source=FBO&limit=1&show_closed=true&api_key=CTrs3pcYimTdR4WKn50aI1GcUxyL9M4s1fyBbSer –