0
Как создать JSON-файл в android? Я хотел бы создать этот вид JSON.android создание и редактирование JSON динамически
{
"contacts": [
{
"id": "c200",
"name": "Ravi Tamada",
"email": "[email protected]",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
},
{
"id": "c201",
"name": "Johnny Depp",
"email": "[email protected]",
"address": "xx-xx-xxxx,x - street, x - country",
"gender" : "male",
},
.
.
.
.
] }
Ну я могу создать JSONObjects, но не могу понять, как обернуть, что в массиве "контакты".
JSONObject json = new JSONObject();
try {
json.put("id", dataList.get(pos).id);
json.put("name", dataList.get(pos).name);
.
.
.
String jsonString = json.toString();
//and then save it
FileOutputStream fos = mContext.openFileOutput("jsonfile", Context.MODE_PRIVATE);
fos.write(jsonString.getBytes());
fos.close();
И когда я буду читать JSON назад, я могу редактировать JSON, например, удаление JSONObject с середины, добавить новый пункт в конце и т.д.?