如何在Android中以这种格式创建JSON:由于我将传递的API将解析JsonArray,然后解析该对象。还是只传递一个json对象就可以了吗?因为我将只需要为每个服务调用插入1个事务。
{
"student": [
{
"id": 1,
"name": "John Doe",
"year": "1st",
"curriculum": "Arts",
"birthday": 3/3/1995
},
{
"id": 2,
"name": "Michael West",
"year": "2nd",
"curriculum": "Economic",
"birthday": 4/4/1994
}
]
}
我所知道的只是JSONObject。像这个。
JSONObject obj = new JSONObject();
try {
obj.put("id", "3");
obj.put("name", "NAME OF STUDENT");
obj.put("year", "3rd");
obj.put("curriculum", "Arts");
obj.put("birthday", "5/5/1993");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
有任何想法吗。谢谢
泛舟湖上清波郎朗
犯罪嫌疑人X
胡子哥哥
相关分类