이 프로젝트는 서버에 연결되어 JSON 응답을받는 호텔에서 일하는 것과 관련이 있습니다. 방 번호를 입력하는 사용자에 대한JSON 파일에서 정보 표시하기
{
"apiVersion": "0.1",
"data": {
"roomCount": 105,
"rooms": [{
"room_number": "104",
"services": [{
"adult": {
"enabled": false
},
"room_charges": {
"enabled": false
}
}],
"status": "OCCUPIED"
}, {
"room_number": "105",
"services": [{
"adult": {
"enabled": true
},
"room_charges": {
"enabled": false
}
}],
"status": "OCCUPIED"
}
내가 만든 형태, 그리고 내가 사용하고 있습니다 : 나는 같은 $output = json_decode($data, true);
그리고이 같은 외모와 협력하고있는 JSON 데이터를 JSON_Decode
를 사용 그 방 번호를 다른 페이지 display_room_report.php
으로 가져 오는 방법은 GET
입니다. 아래에서 작성한 양식을 참조하십시오. 형태
<div id="form1">
<form action="display_room_report.php" method="GET" name="reporting" id="reporting"><br />
<label for="single_room">Enter Room Number</label>
<input type="text" name="id" id="single_room" size="20" required><br><br>
<input style="margin-top: 20px" type="submit" name="submit" id="submit" value="Submit">
</form>
</div>
, 난
display_room_report.php
새로운 페이지에서 JSON 데이터로부터 그 방 번호에 대응하고, 나머지 정보를 표시하고자하고, 방 번호 항목으로
id
를 사용하고있다. 이 코딩을 시도했지만 작동하도록 가져올 수 없습니다. JSON을 사용하는 경우는 거의 없으므로 올바르게 처리하는지 잘 모르겠습니다. 다음과 같이 나는 방 번호를 잡는 오전 :
<?php
if(isset($_GET['id'])){
$id = $_GET['id'];
}
내가 뭘하려는 것은 통해 전달되는 방 번호, 출력을위한 그러한 adult: enabled or disabled
및 room charges: enabled or disabled
같은 방 번호 매개 변수. 그러나, 나는이를 잡아 필요
<?php foreach($output['data']['rooms'] as $info): ?>
<tr>
<td><?php echo $info['room_number']; ?></td>
<?php $services = reset($info['services']); ?>
<td><?php echo ($services['room_charges']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?></td>
<td><?php echo ($services['adult']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?></td>
<td><?php echo $info['status']; ?></td>
</tr>
</body>
<?php endforeach; ?>
을 다음과 같이
try {
$message = "api\tjson\tget\trooms\n";
$handle = fsockopen("192.xxx.xx.xx", 5678);
fwrite($handle, $message);
}
catch (Exception $e) {
echo 'ERRORS: We are unable to connect to the server', $e->getMessage(), "\n";
};
if ($handle == TRUE) {
$data = '';
while (!feof($handle)) {
$data .= fread($handle, 8192);
}
fclose($handle);
$output = json_decode($data, true);
내가 JSON 데이터 정보의 전체 목록을 잡아 수 있습니다 : 나는 다음과 같이 JSON 응답이 얻을 수있는 서버에 연결 특정 id
room_number는 해당 룸 번호의 해당 데이터를 출력합니다. 사용자가 회의실 104에 입장하면 회의실 104의 정보를 페이지에 표시하고 싶습니다. display_room_report.php
감사합니다. 나는 내가하고있는 일에 대해 이해하려고 노력했다.
감사합니다. @ 제이콥! 나는 이걸 직접 봐야했는데, 나는 이것보다 더 복잡 할 것으로 예상했다. 지금 당장은 작동 할 것이며, API에 대한 귀하의 조언도 감사드립니다. – ValleyDigital