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