Android客户端对服务器返回的json文件进行解析
和解析XML的方式大同小异,只有解析方式存在区别:
/**
* 解析服务器返回来的json数据
* @param content
* @return
* @throws Exception
*/
private static List parseJson(String content) throws Exception {
List videoList = new ArrayList();
JSONArray json = new JSONArray(content);
for(int i=0;i
JSONObject item = json.getJSONObject(i);
int id = item.getInt("id");
String name = item.getString("name");
String time = item.getString("time");
Video video = new Video();
video.setId(id);
video.setName(name);
video.setTime(time);
videoList.add(video);
}
return videoList;
}
?