0

私はこのjsonを持っています:

{"data": [{"name" "category" "id" "picture":{"data":{"url":}}}]

私の困難は、画像フィールドを解析する方法です。私はこのコードで試しました:

  public class JSONParser {
        public List<HashMap<String,Object>> parse(JSONObject jObject){      
            JSONArray jGames = null;
                try {       
                    jGames = jObject.getJSONArray("data");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                return getGames(jGames);
            }       
            private List<HashMap<String, Object>> getGames(JSONArray jGames){
                int gameCount = jGames.length();
                List<HashMap<String, Object>> gameList = new ArrayList<HashMap<String,Object>>();
                HashMap<String, Object> game = null;    
                for(int i=0; i<gameCount;i++){
                    try {
                        game = getGame((JSONObject)jGames.get(i));
                        gameList.add(game);

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                return gameList;
            }
            private HashMap<String, Object> getGame(JSONObject jGame){
                HashMap<String, Object> game = new HashMap<String, Object>();
                String gameName = "";
                String logo="";
                String user = "";           
                try {
                    gameName = jGame.getString("name");
                    logo = jGame.getString("logo_url");
                    user = jGame.getString("daily_active_users");
                    String details ="Utenti attivi : " + user + "\n";
                    game.put("name", gameName);
                    game.put("logo_url", R.drawable.icon);
                    game.put("logo_path", logo);
                    game.put("details", details);
                } catch (JSONException e) {         
                    e.printStackTrace();
                }       
                return game;
            }
        }
4

1 に答える 1

0

このチュートリアルはあなたに役立ちますAndroid JSON Parsing Tutorial

于 2013-04-17T14:00:12.270 に答える