我是第一次在android中开发,我以前从未使用过json数据。我将开发一份我校活动日历的应用程序。我们在Django中开发了web版本应用程序,我们实现了tastypie (restapi),所以我需要在android移动版本中使用这个json数据。我的json数据是这样的:
{
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 5
},
"objects": [{
"Location": "Z011",
"Notes": "asdf",
"Title": "Literature Talking",
"id": 3,
"resource_uri": "/api/v1/Events/3/"
}, {
"Location": "Batı Kampüsü, Sinema Salonua",
"Notes": "sd",
"Title": "TARİHÇE KONFERANSLARI SERİSİ 25",
"id": 4,
"resource_uri": "/api/v1/Events/4/"
}, {
"Location": "in Campus",
"Notes": "afafdf",
"Title": "Self-Assessment Project",
"id": 5,
"resource_uri": "/api/v1/Events/5/"
}, {
"Location": "Kütüphane",
"Notes": "fs",
"Title": "51.Kütüphane Haftası",
"id": 6,
"resource_uri": "/api/v1/Events/6/"
}]
}如何在android中解析Json数据?
发布于 2015-05-21 11:30:13
使用下面的代码,您将能够获得标题和Location
JSONObject obj=new JSONObject(response);//This is response from webservice
String totalCount = obj.getJSONObject("meta").getString("total_count"); //for getting total_count
JSONArray json_array = obj.getJSONArray("objects");
for(int j=0;j<json_array.length();j++) {
String title = json_array.getJSONObject(j).getString("Title");
String location= json_array.getJSONObject(j).getString("Location");
}发布于 2015-05-12 17:00:07
使用此网站可以帮助您更好地查看Json结构。
http://www.jsontree.com/
您所拥有的是Json对象,因为它以大括号开头和结尾。
例如,如果我将Json作为{"Id":"1"},则键为"Id“,值为"1”
Json对象也可以在值中包含一个Json (这是您的情况)。
以{"Id":{"Place1":"1", "Place2":"2"}}为例
所以关键是"Id",它有值"Place1":"1", "Place2":"2"
所以这个值也是一个Json。
这可能会让Jsons的生活变得有点混乱。
下面是解析Json的一个很好的教程
parser.htm
https://stackoverflow.com/questions/30192970
复制相似问题