Code example for JSONArray

Methods: getlength

	 * 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();
			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) {
			return false; 
Stop searching for code, let great code find you!  Add Codota to your java IDE