아래보시면 웹에서 만들어 확인까지 된 jsonarray입니다
안드로이드에서는
java.lang.IllegalArgumentException: size <= 0
(HTTPLog)-Static: isSBSettingEnabled false 같은 에러가 뜹니다 ㅠㅠ...
onPostExecute에서 전달받은 str를 찍어보면 아무런값이 없습니다.
웹에서는 확인이 가능한데 안드로이드에서 파일을 못 읽습니다 이유를 알 수 있을까요 ?
참고로 gettingPHP함수를 하나더 만들어 다른 페이지를 불러올때는 잘 됩니다 ㅠㅠ....
============================
[{"dsTime":"2017-06-06 00:10:00","dsUV":"0.8"},{"dsTime":"2017-06-06 00:13:09","dsUV":"0.9"},{"dsTime":"2017-06-06 00:16:01","dsUV":"1.3"}]
static String url = "http://211.226.214.248/getinfo.php";
gPHP = new GettingPHP();
gPHP.execute(url,acode);
class GettingPHP extends AsyncTask<String, Integer, String> {
@Override
// php에서 데이터를 읽어옴
protected String doInBackground(String... params) {
StringBuilder jsonHtml = new StringBuilder();
try {
URL phpUrl = new URL(params[0]);
Log.d("test", params[0] + "" + params[1] + "");
String body = "&acode=" + params[1];
HttpURLConnection conn = (HttpURLConnection) phpUrl.openConnection();
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
OutputStream os = conn.getOutputStream();
os.write(body.getBytes("utf-8"));
os.flush();
os.close();
//BufferedReader br = new BufferedReader( new InputStreamReader( conn.getInputStream(), "EUC-KR" ), conn.getContentLength() );
String buf;
if (conn != null) {
if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"), conn.getContentLength());
while (true) {
String line = br.readLine();
if (line == null)
break;
Log.d("line", line);
jsonHtml.append(line + "\n");
}
br.close();
}
conn.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
}
Log.d("jsonHTML", jsonHtml.toString());
return jsonHtml.toString();
}
// 가져온 데이터를 이용해 개발자가 원하는 일을 작성
public void onPostExecute(String str) {
try {
JSONArray results;
results = new JSONArray(str);
for (int i = 0; i < results.length(); i++) {
JSONObject temp = results.getJSONObject(i);
score_uv = temp.getDouble("dsUV");
raw_time = temp.getString("dsTime");
raw_uv = String.valueOf(score_uv);
uv.setText(raw_uv);
timeView.setText(raw_time);
}
// 지수에 따라서 이모티콘 이미지 변함
if (score_uv > 0) image.setImageResource(R.drawable.sun_green);
else if (score_uv > 4) image.setImageResource(R.drawable.sun_orange);
else if (score_uv >= 6) image.setImageResource(R.drawable.sun_red);
} catch (JSONException e) {
e.printStackTrace();
}
}
}