【发布时间】:2014-02-20 15:09:55
【问题描述】:
我很少有用户在其中输入详细信息的对话框(个人详细信息-名字、姓氏等),我需要捕获详细信息并转换为 JSON。 用户可以输入多个人的详细信息,例如。 person1、person2、person3(应该是 JSONObjects)。当我第一次调用波纹管函数时 JSONObject personJSON1 = new JSONObject(); 第二次叫它 JSONObject personJSON2 = new 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的列表,并为每个新人添加一个新元素到列表中。 -
你能推荐任何 JSONObject 列表的链接或示例
标签: android json arrays jsonobject