Code example for JSONArray

Methods: getJSONObject, length

0
        if (serversText.equals("")) {
            return new ArrayList<Server>();
        } 
        try { 
            ArrayList<Server> servers = new ArrayList<Server>();
            JSONArray serversJson = new JSONArray(serversText);
            for (int i = 0; i < serversJson.length(); i++) {
                final JSONObject serverJson = serversJson.getJSONObject(i);
                servers.add(new Server() {{
                    appid = serverJson.getString("appid");
                    path = serverJson.getString("path");
                    password = serverJson.getString("password");
                }}); 
            } 
            return servers;
        } catch (Exception e) {
            LogUtils.e("failed to parse: " + serversText, e);
            return new ArrayList<Server>();
        } 
    }