Я устанавливаю простой обработчик PHP для моих файлов json.
Вот мои настройки, я не уверен точно, что мне нужно определить в моем PHP-скрипте, чтобы получить этот идентификатор из длинного списка в json.
Любое предложение или помощь будут оценены.
<?php
$id = $_GET['id']; //get ?id=
$jsonurl = "api/documents.json"; //json path
$json = file_get_contents($jsonurl); //getting file
$decode = json_decode($json); //decoding the json
$echome = $decode[0]->$id; //looking for "id" within the json
$reencode = json_encode($echome) //re-encoding this segmented json
echo($reencode); //echo the json
Желаемый результат будет
//load page with id set as 21
{
"21": {
"name": "mike",
"active": "yes"
}
}
url = www.example.com/process.php?id=21
// simple example of the json
{
"20": {
"name": "john",
"active": "no"
},
"21": {
"name": "mike",
"active": "yes"
}
}