RxNetworking - GET, PATH, HEADER
Installation link here : http://rxandroid.blogspot.in/2018/03/rxnetworking-installation-and.html
In Below Code - Pagination work happen
AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllUsers/{pageNumber}") .addPathParameter("pageNumber", "0") .addQueryParameter("limit", "3") .addHeaders("token", "1234") .setTag("test") .setPriority(Priority.LOW) .build() .getAsJSONArray(new JSONArrayRequestListener() { @Override public void onResponse(JSONArray response) { // do anything with response for(int i = 0; i < response.length(); i++){ try { // System.out.println("Output --> "+response.get(i));// JSONObject jsonObject = response.getJSONObject(i); int id = jsonObject.getInt("id"); String firstName = jsonObject.getString("firstname"); String lastName = jsonObject.getString("lastname"); System.out.println("Output --> "+id); System.out.println("Output --> "+firstName); System.out.println("Output --> "+lastName); } catch (JSONException e) { e.printStackTrace(); } } } @Override public void onError(ANError error) { // handle error System.out.println(error); } });
NOTE -
1. For JSONArray
getAsJSONArray(new JSONArrayRequestListener() {
@Override public void onResponse(JSONArray response) {
}
}
2. For JSONObjectgetAsJSONObject(new JSONObjectRequestListener() {@Override public void onResponse(JSONObject response) {}}
Comments
Post a Comment