Android 创建嵌套的JSON对象
示例
要生成嵌套的JSON对象,您只需将一个JSON对象添加到另一个对象即可:
JSONObject mainObject = new JSONObject(); // 主对象
JSONObject requestObject = new JSONObject(); // 包含对象
try {
requestObject.put("lastname", lastname);
requestObject.put("phone", phone);
requestObject.put("latitude", lat);
requestObject.put("longitude", lon);
requestObject.put("theme", theme);
requestObject.put("text", message);
mainObject.put("claim", requestObject);
} catch (JSONException e) {
return "JSON Error";
}现在mainObject包含一个claim以整体requestObject为值的键。