1 回答

TA貢獻1809條經驗 獲得超8個贊
您可以嘗試以下方式
try {
JSONObject obj=new JSONObject();
obj.put("id", 58);
JSONObject contact=new JSONObject();
contact.put("id", "smome value");
contact.put("first_line", "smome value");
contact.put("locality", "smome value");
JSONObject address=new JSONObject();
address.put("primary_number", "primary");
address.put("secondary_number", "secondary");
obj.put("address", address);
obj.put("contact", contact);
}catch (Exception e) {
e.printStackTrace();
}
現在輸出如下所示
{
"id": 58,
"address": {
"primary_number": "primary",
"secondary_number": "secondary"
},
"contact": {
"first_line": "smome value",
"locality": "smome value",
"id": "smome value"
}
}
添加回答
舉報