You could have type the parameter and the result as JSONObject and avoid these castings.