학교 건물에서 기계공 용 Android 애플리케이션을 만들고 있습니다. 학생들은 방의 QR 코드를 스캔하여 수업 룸에서 문제가 발생했는지 확인해야합니다 (예 : 비머가 고정되어야 함). 이 문제를 수정 한 후에는 다른 사용자에게이 작업이 완료되었음을 알리는 확인란을 true로 설정할 수 있습니다.JSON 파일의 변경 사항 저장 Android
내 정보를 얻기 위해 json 파일을 사용하고 있으므로 사용자가 체크 박스를 선택하면 json 파일을 업데이트해야합니다. 많이 시도했지만 해결 방법을 찾지 못했습니다.
누군가 나를 도와 줄 수 있습니까?
이 내가 알고있는 것입니다 ..
finished.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
checked = true;
} else {
checked = false;
}
}
});
if (checked) {
//JSONObject modified = new JSONObject();
try {
JSONArray d = new JSONArray();
JSONObject tour;
tour = new JSONObject();
tour.put("done" + (i + 1), "Yes");
d.put(tour);
String text = data.toString();
FileOutputStream fos = openFileOutput("tours", MODE_PRIVATE);
fos.write(text.getBytes());
fos.close();
} catch (JSONException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
//JSONObject modified = new JSONObject();
try {
JSONArray d = new JSONArray();
JSONObject tour;
tour = new JSONObject();
tour.put("done" + (i + 1), "No");
d.put(tour);
String text = data.toString();
FileOutputStream fos = openFileOutput("tours", MODE_PRIVATE);
fos.write(text.getBytes());
fos.close();
} catch (JSONException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}