JSON 텍스트를 생성하는 간단한 PHP 페이지를 개발하여 응용 프로그램을 테스트 할 수있었습니다. 실제 서버는 다른 사람이 개발했기 때문에 이상한 오류가 있습니다.웹 서비스가 JSON 대신 <br />이되었습니다
<?php
header('Content-type: application/json');
$trip = array ('trip' => array (array ('departureStation' => $_GET['from'],
'arriveStation' => $_GET['to'],
'departureTime' => '08:00',
'arriveTime' => '11:00',
'date' => $_GET['date'],
'duration' => '3',
'distance' => '80',
'price' => '5',
'changeLine' => false,
'waitTime' => '0',
'passengers' => '13'),
array ('departureStation' => $_GET['from'],
'arriveStation' => $_GET['to'],
'departureTime' => '11:00',
'arriveTime' => '14:00',
'date' => $_GET['date'],
'duration' => '3',
'distance' => '80',
'price' => '5',
'changeLine' => false,
'waitTime' => '0',
'passengers' => '29'),
array ('departureStation' => $_GET['from'],
'arriveStation' => $_GET['to'],
'departureTime' => '17:00',
'arriveTime' => '20:00',
'date' => $_GET['date'],
'duration' => '3',
'distance' => '80',
'price' => '5',
'changeLine' => false,
'waitTime' => '0',
'passengers' => '45')));
echo json_encode($trip);
?>
내가 확인하고 유효한 JSON을 반환하지만 내가
URL url = new URL("http://xxx.xxx.x.xx/consult.php" + param);
con = (HttpURLConnection) url.openConnection();
con.setReadTimeout(10000); /* milliseconds */
con.setConnectTimeout(15000); /* milliseconds */
con.setRequestMethod("GET");
con.setDoInput(true);
con.connect();
BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
payload = reader.readLine();
을 수행 할 때 페이로드 변수 만 얻을 나는 그것을 알고 <br />
가 뭔가 : 내 PHP 페이지에만이있다 PHP에서 내가 페이지에 입력했기 때문에 출력을 복사하고 PHP 코드를 다시보고 그냥 넣으십시오.
$echo 'json_copied_from_the_page_here';
이 작동하고 페이로드가 페이지를 올바르게 읽습니다. 그래서 궁금해서 왜 이런 일이 일어 났습니까?
wireshark 및 에뮬레이터를 사용하여 다운로드 할 항목을 선택하십시오. – rekire