Example usage for org.json JSONArray getString

List of usage examples for org.json JSONArray getString

Introduction

In this page you can find the example usage for org.json JSONArray getString.

Prototype

public String getString(int index) throws JSONException 

Source Link

Document

Get the string associated with an index.

Usage

From source file:com.piggate.sdk.Piggate.java

public Request RequestNewUser(RequestParams params) {

    final Request request = new Request(this);
    request._method = "POST"; //define the request method
    params.put("app", APP_ID);
    request._params = params; //define the params
    request._url = "client/signup"; //define the url to do the request

    request._precallable = new PreCallable() {
        @Override//from   w  w w .ja  va 2 s  .  com
        public void call() {
            reload();
        }
    };

    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        //Take the error message to return to the user
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {
            String msg = "";
            if (response != null) {
                try {
                    msg = response.getString("error");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            if (request._callBack != null) {
                request._callBack.onError(statusCode, headers, msg, (JSONObject) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            String msg = "";
            JSONObject obj = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    obj = response.getJSONObject("data");
                    PiggateUser.getInstance(obj.getString("_id"), obj.getString("email"));
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, obj);
            }
        }

        //Handle the request success for JSONArray
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
        }
    };
    return request;
}

From source file:com.piggate.sdk.Piggate.java

public Request RequestOpenSession(RequestParams params) {
    final Request request = new Request(this);
    request._method = "POST"; //define the request method
    params.put("app", APP_ID);
    request._params = params; //define the params
    request._url = "client/login"; //define the url to do the request

    request._precallable = new PreCallable() {
        @Override// www .  j a va  2 s. c o  m
        public void call() {
            reload();
        }
    };

    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {
            String msg = "";

            if (response != null) {
                try {
                    msg = response.getString("error");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            PiggateUser.getInstance(null, null);
            if (request._callBack != null) {
                request._callBack.onError(statusCode, headers, msg, (JSONObject) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

            String msg = "";
            JSONObject obj = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    obj = response.getJSONObject("data");
                    PiggateUser.getInstance(obj.getString("_id"), obj.getString("email"));
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }

            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, obj);
            }
        }

        //Handle the request success for JSONArray
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            //Unused
        }
    };
    return request;
}

From source file:com.piggate.sdk.Piggate.java

public Request RequestCloseSession() {
    final Request request = new Request(this);
    request._method = "GET"; //define the request method
    request._params = null; //define the params
    request._url = "client/logout"; //define the url to do the request

    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override//from w w w .  j a va 2  s .  c  om
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {
            String msg = "";
            JSONObject obj = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    msg = response.getString("error");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            PiggateUser.getInstance(null, null);

            if (request._callBack != null) {
                request._callBack.onError(statusCode, headers, msg, (JSONObject) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            String msg = "";
            Object obj = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    obj = response.getString("data");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            PiggateUser.getInstance(null, null);

            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, (JSONObject) null);
            }
        }

        //Handle the request success for JSONArray
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            //Unused
        }
    };
    return request;
}

From source file:com.piggate.sdk.Piggate.java

public Request RequestOffers(final PiggateBeacon beacon) {
    final Request request = new Request(this);

    request._method = "GET"; //Define the request method
    request._params = null; //Define the params
    request._url = "client/get/ibeacon/major/" + beacon.getMajor() + "/minor/" + beacon.getMinor(); //Define the url
    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override/*  w w  w.  j a  v a2  s.c  o m*/
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        //Return a message to the user
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {

            String msg = "";
            JSONObject obj = null;
            if (response != null) { // If the response is JSONObject instead of expected JSONArray
                try {
                    msg = response.getString("error");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            if (request._callBack != null) {
                PiggateBeacon.addPendingBeacons(new ArrayList<>(Arrays.asList(beacon)));
                request._callBack.onError(statusCode, headers, msg, (JSONArray) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

            String msg = "";
            JSONObject obj = null;
            JSONArray offers = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    obj = response.getJSONObject("data");
                    offers = obj.getJSONArray("offers");

                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, (JSONArray) offers);
                //Add the offers to the registry
                PiggateOffers.addOffers(offers);
            }
        }

        //Handle the request success for JSONArray
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            //Unused
        }
    };
    return request;
}

From source file:com.piggate.sdk.Piggate.java

public Request RequestUser() {
    final Request request = new Request(this);
    request._method = "GET"; //Define the request method
    request._params = null; //Define the params
    request._url = "client"; //Define the url

    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override//  w  w  w.ja  va  2 s  .co  m
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        //return a message to the user
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {

            String msg = "";
            JSONObject obj = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    msg = response.getString("error");
                    PiggateUser.getInstance(null, null);

                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }

            if (request._callBack != null) {
                request._callBack.onError(statusCode, headers, msg, (JSONObject) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            String msg = "";
            JSONObject obj = null;
            if (response != null) { // If the response is JSONObject instead of expected JSONArray
                try {
                    obj = response.getJSONObject("data");
                    PiggateUser.getInstance(obj.getString("_id"), obj.getString("email"));
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, obj);
            }
        }

        //Handle the request success for JSONArray
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            //Unused
        }
    };
    return request;
}

From source file:com.piggate.sdk.Piggate.java

public Request RequestGetNotification() {
    final Request request = new Request(this);
    request._method = "GET"; //define the request method
    request._params = null; //define the params
    request._url = "client/get/notification"; //define the url to do the request

    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override//  w w  w.j a va 2  s.  c  o m
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {
            String msg = "";
            JSONObject obj = null;

            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    msg = response.getString("error");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }

            if (request._callBack != null) {
                request._callBack.onError(statusCode, headers, msg, (JSONObject) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            String msg = "";
            JSONObject obj = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    obj = response.getJSONObject("data");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }

            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, obj);
            }
        }

        //Handle the request success for JSONArray
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            //Unused
        }
    };
    return request;
}

From source file:com.piggate.sdk.Piggate.java

public Request RequestBuy(RequestParams params) {
    final Request request = new Request(this);

    request._method = "POST"; //define the request method
    request._params = params; //define the params
    request._url = "stripe/charge"; //define the url to do the request (WILL CHANGE TO client/stripe/charge)

    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override/* ww  w .j  av  a  2 s.  c om*/
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        //Take the error message to return to the user
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {

            String msg = "";
            if (response != null) {
                try {
                    msg = response.getString("error");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            if (request._callBack != null) {
                request._callBack.onError(statusCode, headers, msg, (JSONObject) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

            String msg = "";
            JSONObject obj = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    obj = response.getJSONObject("data");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, obj);
            }
        }

        //Handle the request success for JSONArray
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            //Unused
        }
    };

    return request;
}

From source file:com.piggate.sdk.Piggate.java

public Request RequestGetExchange() {
    final Request request = new Request(this);
    request._method = "GET"; //define the request method
    request._params = null; //define the params
    request._url = "client/exchange"; //define the url to do the request

    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override//from  ww  w.j a  v  a 2  s.  c  om
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {
            String msg = "";
            JSONObject obj = null;

            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    msg = response.getString("error");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }

            if (request._callBack != null) {
                request._callBack.onError(statusCode, headers, msg, (JSONObject) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            String msg = "";
            JSONArray obj = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    obj = response.getJSONArray("data");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }

            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, obj);
            }
        }

        //Handle the request success for JSONArray
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            //Unused
        }
    };
    return request;
}

From source file:com.piggate.sdk.Piggate.java

public Request RequestExchange(RequestParams params, String offerID) {
    final Request request = new Request(this);

    request._method = "POST"; //define the request method
    request._params = params; //define the params
    request._url = "client/exchange/" + offerID; //define the url to do the request with the offer ID

    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override//from  www .  ja  v  a2s  .c  o  m
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        //Take the error message to return to the user
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {

            String msg = "";
            if (response != null) {
                try {
                    msg = response.getString("error");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            if (request._callBack != null) {
                request._callBack.onError(statusCode, headers, msg, (JSONObject) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

            String msg = "";
            JSONObject obj = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    obj = response.getJSONObject("data");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {
                } catch (NullPointerException a) {
                }
            }
            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, obj);
            }
        }

        //Handle the request success for JSONArray
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            //Unused
        }
    };

    return request;
}

From source file:com.piggate.sdk.Piggate.java

public Request RequestInfo(final PiggateBeacon beacon) {
    final Request request = new Request(this);

    request._method = "GET"; //Define the request method
    request._params = null; //Define the params
    request._url = "client/get/ibeacon/major/" + beacon.getMajor() + "/minor/" + beacon.getMinor(); //Define the url
    //Handle the request events (if the request fail or is correct)
    request._rest_callback = new JsonHttpResponseHandler() {

        //Handle the request error for JSONArray
        @Override//from  ww w  . j ava  2 s. c  o  m
        public void onFailure(int statusCode, Header[] headers, Throwable e, JSONArray response) {
            //Unused
        }

        //Handle the request error for JSONObject
        //Return a message to the user
        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject response) {

            String msg = "";
            JSONObject obj = null;
            if (response != null) { // If the response is JSONObject instead of expected JSONArray
                try {
                    msg = response.getString("error");
                } catch (JSONException a) {

                } catch (NullPointerException a) {

                }
            }
            if (request._callBack != null) {
                PiggateBeacon.addPendingBeacons(new ArrayList<>(Arrays.asList(beacon)));
                request._callBack.onError(statusCode, headers, msg, (JSONArray) null);
            }
        }

        //Handle the request success for JSONObject
        //Return a message to the user
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

            String msg = "";
            JSONObject obj = null;
            JSONArray obj2 = null;
            // If the response is JSONObject instead of expected JSONArray
            if (response != null) {
                try {
                    obj = response.getJSONObject("data");
                    obj2 = obj.getJSONArray("info");
                } catch (JSONException a) {

                } catch (NullPointerException a) {

                }
                try {
                    msg = response.getString("success");
                } catch (JSONException a) {

                } catch (NullPointerException a) {

                }
            }
            if (request._callBack != null) {
                request._callBack.onComplete(statusCode, headers, msg, (JSONArray) obj2);
                //Add the information tickets to the registry
                PiggateInfo.addInfo(obj2);
            }
        }

        //Handle the request success for JSONArray
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONArray response) {
            //Unused
        }
    };
    return request;
}