所以我想用PHP搜索JSON文件。 json鏈接:http://media1.clubpenguin.com/play/en/web_service/game_configs/paper_items.json。我只是把JSON文件放入我的網絡服務器。下面我的腳本:閱讀JSON文件?
<?php
$query = $_GET['s'];
$terms = explode(' ', $query);
$results = array();
foreach(file('items.json') as $line) {
$found = true;
foreach($terms as $term) {
if(strpos($line, $term) == false) {
$found = false;
break;
}
}
if($found) {
$results[] = $line;
} else {
}
}
print_r($results);
問題是它顯示了整個json文件而不是我的$查詢。我能做些什麼來解決這個問題?
[json_decode(http://www.php.net/json_decode]可能是你在找什麼嘗試'json_decode(的file_get_contents( 「items.json」),TRUE);' – Orangepill
不,只是一堆的錯誤 – Timmy6118CP
什麼數據是你打算通過搜索? – Orangepill