Page 924 - 3-2
P. 924
// 커넥션 객체 생성
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// 연결되었으면.
Log.d(this.getClass().getName(), "url 접근");
if (conn != null) {
Log.d(this.getClass().getName(), "1 접근");
conn.setUseCaches(false);
// 연결되었음 코드가 리턴되면.
Log.d(this.getClass().getName(), "2 접근");
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
Log.d(this.getClass().getName(), "3 접근");
BufferedReader br = new BufferedReader
(new InputStreamReader(conn.getInputStream(), "UTF-8"));
Log.d(this.getClass().getName(), "4 접근");
for (; ; ) {
// 웹상에 보여지는 텍스트를 라인단위로 읽어 저장.
Log.d(this.getClass().getName(), "5 접근");
String line = br.readLine();
Log.d(this.getClass().getName(), "6 접근");
if (line == null) break;
// 저장된 텍스트 라인을 jsonHtml 에 붙여넣음
Log.d(this.getClass().getName(), "7 접근");
jsonHtml.append(line + "\n");
Log.d(this.getClass().getName(), " 연결 완료");
}br.close();
Log.d(this.getClass().getName(), "br close");
}conn.disconnect();
Log.d(this.getClass().getName(), " 연결 끝");
}
} catch (Exception ex) {
ex.printStackTrace();
Log.d(this.getClass().getName(), " 연결 실패");
}
try {
JSONObject root = new JSONObject(jsonHtml.toString());
JSONArray ja = root.getJSONArray("results");
ja1 = ja.length();
if(notFlag==0) {
for (int i = 0; i < ja.length(); i++) {
JSONObject jo = ja.getJSONObject(i);
if (jo.getString("room").equals(MainActivity.room) &&
jo.getString("addr").equals(MainActivity.callval))
- 924 -