我有几个用户在其中输入他们的详细信息(人员详细信息 - 名字,姓氏等)的对话框,我需要捕获细节并转换为JSON。 用户可以输入多个人的详细信息。 person1,person2,person3(应该是JSONObjects)。当我第一次调用下面的函数时,我想要 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