[英]how to get only specific data we want from json
我無法加載一些數據,我已經有了數據庫,並且有查詢名稱“tipe”(類型),在查詢中,tipe 只有 2 種類型的字符串(“1”和“2”)所以,如果我只想加載,如何加載數據特定數據類型=“1”....
這是我在 android 中的代碼:
電影片段.java
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
Movie movie = new Movie();
movie.setTitle(obj.getString("name"));
movie.setThumbnailUrl(obj.getString("images1"));
//movie.setDescribe(obj.getString("describe"));
//movie.setRating(((Number) obj.get("rating"))
// .doubleValue());
movie.setYear(obj.getInt("id"));
movie.setTipe(obj.getString("tipe"));
/*// Genre is json array
JSONArray genreArry = obj.getJSONArray("genre");
ArrayList<String> genre = new ArrayList<String>();
for (int j = 0; j < genreArry.length(); j++) {
genre.add((String) genreArry.get(j));
}
movie.setGenre(genre);*/
// adding movie to movies array
movieList.add(movie);
} catch (JSONException e) {
e.printStackTrace();
}
}
我會嘗試這樣的事情:
// Parsing json
for (int i = 0; i < response.length(); i++) {
try {
JSONObject obj = response.getJSONObject(i);
if (obj.getString("tipe").equals("tipe1){
Movie movie = new Movie();
movie.setTitle(obj.getString("name")); movie.setThumbnailUrl(obj.getString("images1"));
movie.setYear(obj.getInt("id"));
movie.setTipe(obj.getString("tipe"));
// adding movie to movies array
movieList.add(movie);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.