所以我有一些相對簡單的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 –