我正在爲學校建築中的機制創建一個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();
}
}