public void op() {
StringBuilder sb = new StringBuilder();
// int code = intent.getIntExtra("code", 0);
String ch;
String ch2;
try {
URL url = new URL("http://sjbc.tv/test/op.php?num=" + code);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
if (conn != null) {
conn.setConnectTimeout(10000);
conn.setUseCaches(false);
status.setText(String.valueOf(conn.getResponseCode()) + "\n"
+ String.valueOf(HttpURLConnection.HTTP_OK));
status2.setText(String.valueOf(conn.getResponseCode()) + "\n"
+ String.valueOf(HttpURLConnection.HTTP_OK));
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
while (true) {
String line = br.readLine();
if (line == null)
break;
sb.append(line + "\n");
}
br.close();
} else {
status.setText("http_not");
status2.setText("http_not");
}
conn.disconnect();
}
} catch (Exception e) {
// status.setText(e.toString());
status.setText(e.toString());
status2.setText(e.toString());
}
String jsonString = sb.toString();
try {
int data1 = 0;
int data2 = 0;
JSONArray ja = new JSONArray(jsonString);
/*
* for (int i = 0; i < ja.length(); i++) {
*
* JSONObject jo = ja.getJSONObject(i); // 결과물
*
* data2 += jo.getInt("cb1_status"); } status2.setText(data2);
*/
data1 = ja.getJSONObject(0).getInt("cb1_status");
data2 = ja.getJSONObject(1).getInt("cb1_status");
// 결과 출력
if (data1 == 1) {
ch = "가동중";
status.setText(ch);
return;
} else if (data1 == 0) {
ch = "정지";
status.setText(ch);
return;
}
if (data2 == 1) {
ch2 = "가동중";
status2.setText(ch2);
} else if (data2 == 0) {
ch2 = "정지";
status2.setText(ch2);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
status.setText(e.toString());
status2.setText(e.toString());
}
}
현재 DB값을 불러와서 status 라는 텍스트뷰에 하나
status2 라는 텍스트뷰에 하나를 가져와야되는데
status 의 값을 잘 가지고 와서 값이 1이 들어와 가동중으로 뜨고있습니다
그러나 똑같이 한건데 status2의 값은 200200 으로 뜨고있습니다
뭐가 잘못된거죠??