Example usage for org.json JSONArray getInt

List of usage examples for org.json JSONArray getInt

Introduction

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

Prototype

public int getInt(int index) throws JSONException 

Source Link

Document

Get the int value associated with an index.

Usage

From source file:org.brickred.socialauth.provider.TwitterImpl.java

/**
 * Gets the list of followers of the user and their screen name.
 * //from  w w w .j a v a2 s. c  o m
 * @return List of contact objects representing Contacts. Only name, screen
 *         name and profile URL will be available
 */
@Override
public List<Contact> getContactList() throws Exception {
    if (!isVerify) {
        throw new SocialAuthException("Please call verifyResponse function first to get Access Token");
    }
    String url = String.format(CONTACTS_URL, accessToken.getAttribute("screen_name"));
    List<Contact> plist = new ArrayList<Contact>();
    LOG.info("Fetching contacts from " + url);
    Response serviceResponse = null;
    try {
        serviceResponse = authenticationStrategy.executeFeed(url);
    } catch (Exception ie) {
        throw new SocialAuthException("Failed to retrieve the contacts from " + url, ie);
    }
    String result;
    try {
        result = serviceResponse.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
        throw new ServerDataException("Failed to get response from " + url);
    }
    LOG.debug("User friends ids : " + result);
    try {
        JSONObject jobj = new JSONObject(result);
        if (jobj.has("ids")) {
            JSONArray idList = jobj.getJSONArray("ids");
            int flength = idList.length();
            int ids[] = new int[flength];
            for (int i = 0; i < idList.length(); i++) {
                ids[i] = idList.getInt(i);
            }
            if (flength > 0) {
                if (flength > 100) {
                    int i = flength / 100;
                    int temparr[];
                    for (int j = 1; j <= i; j++) {
                        temparr = new int[100];
                        for (int k = (j - 1) * 100, c = 0; k < j * 100; k++, c++) {
                            temparr[c] = ids[k];
                        }
                        plist.addAll(lookupUsers(temparr));
                    }
                    if (flength > i * 100) {
                        temparr = new int[flength - i * 100];
                        for (int k = i * 100, c = 0; k < flength; k++, c++) {
                            temparr[c] = ids[k];
                        }
                        plist.addAll(lookupUsers(temparr));
                    }
                } else {
                    plist.addAll(lookupUsers(ids));
                }
            }
        }
    } catch (Exception e) {
        throw new ServerDataException("Failed to parse the user friends json : " + result, e);
    }
    return plist;
}

From source file:com.sesamtv.cordova.chromecast.ChromeCast.java

private void setReceiverAction(JSONArray args, final CallbackContext callbackContext) throws JSONException {

    final int index = args.getInt(0);
    setReceiverCallback = callbackContext;

    cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            final RouteInfo route = mMediaRouter.getRoutes().get(index);

            Log.d(TAG, "route :" + index + " " + route.getId() + " selected " + route.isSelected()
                    + " playback type: " + route.getPlaybackType());

            try {
                if (route.isSelected()) {
                    Log.d(TAG, "found selected route");
                    //mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());
                    //mMediaRouter.selectRoute(route);

                    mSelectedDevice = CastDevice.getFromBundle(route.getExtras());
                    onReceiverListChanged();
                    launchReceiver();//from   w w w.j a  v a2  s .c  om

                } else {
                    mMediaRouter.selectRoute(route);
                }
            } catch (Exception e) {
                callbackContext.error(e.getMessage());
            }
        }
    });

}