사용자가 세부 정보 (사람 세부 정보 - 이름, 성 등)를 입력하는 대화 상자가 거의 없으므로 세부 정보를 캡처하고 JSON으로 변환해야합니다. 사용자는 여러 명을 입력 할 수 있습니다. person1, person2, person3 (JSONObject이어야 함). 언제든지 처음으로 벨로우 함수가 호출 될 때 JSONObject personJSON1 = new JSONObject(); 두 번째로 호출 됨 JSONObject personJSON2 = new JSONObject(); 등등. 어떻게하면 좋을까요?JSONObject의 이름을 동적으로 변경하는 방법
private void personAdded() {
JSONObject personJSON = new JSONObject();
JSONArray personArrayjson = new JSONArray();
JSONObject personObjectJson = new JSONObject();
try {
personObjectJson.put("otherFirstName", sOtherFirstName);
personObjectJson.put("otherLastName", sOtherLastName);
personObjectJson.put("otherAddress", sOtherAddress);
personObjectJson.put("otherTown", sOtherTown);
personObjectJson.put("otherCounty", sOtherCounty);
personObjectJson.put("otherPostcode", sOtherPostcode);
personObjectJson.put("otherTelephone", sOtherTelephone);
personObjectJson.put("otherMobilePhone", sOtherMobilePhone);
personObjectJson.put("otherEmail", sOtherEmail);
personObjectJson.put("otherPersonInvolvement", sHowWasTheOtherPersonInvolved);
} catch (JSONException e) {
e.printStackTrace();
}
}
많은 도움과 제안을 주셨습니다. 고맙습니다.
당신은'JSONObject'의 목록을 사용할 수 있고 새로운 사람마다 목록에 새로운 요소를 추가 할 수 있습니다. – user3182577
JSONObject – BRDroid