如何解析嵌套的json obiect

时间:2022-10-22 20:37:10

I've this json:

我这个json:

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

{“数据”:[{“名称”“类别”“id”“图片”:{“数据”:{“url”:} } })

My difficulty is how to parse the picture field. I tried with this code:

我的困难是如何解析图片字段。我试着用这段代码:

  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;
            }
        }

1 个解决方案

#1


0  

this tutorial will help you Android JSON Parsing Tutorial

本教程将帮助您了解Android JSON解析教程

#1


0  

this tutorial will help you Android JSON Parsing Tutorial

本教程将帮助您了解Android JSON解析教程