Code example for JSONArray

Methods: get, length

0
	 * Updates the data in the database based upon the players supplied by the server. 
	 * @param players A JSONArray containing the JSONObjects for each player. 
	 * @return True if the operation succeeded, false otherwise. 
	 */ 
	public boolean updatePlayerTable(JSONArray players) {
		int numPlayers = players.length();
		try{ 
			for(int i = 0; i < numPlayers; i++) {
				JSONObject player = (JSONObject) players.get(i);
				int pk = player.getInt("pk");
				if (hasPlayer(pk)) {
					updatePlayer(pk, player.getJSONObject("fields"));
				} else { 
					insertPlayer(pk, player.getJSONObject("fields"));
				} 
			} 
			return true; 
		} catch (JSONException e) {
			e.printStackTrace();
			return false; 
		}