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.github.mhendred.face4j.model.Group.java

public Group(final JSONObject jObj) throws JSONException {
    this.gid = jObj.optInt("gid");
    this.uid = jObj.optString("uid");

    this.tids = new LinkedList<String>();

    final JSONArray jArr = jObj.getJSONArray("tids");

    for (int i = 0; i < jArr.length(); i++) {
        tids.add(jArr.getString(i));
    }//from   w  w w . j ava2  s.c  o  m
}

From source file:se.frostyelk.cordova.parse.plugin.ParsePlugin.java

/**
 * This is the main method for the Parse Plugin. All API calls go through
 * here. This method determines the action, and executes the appropriate
 * call./*w  w w .j a  v  a  2 s .com*/
 *
 * @param action          The action that the plugin should execute.
 * @param args            The input parameters for the action.
 * @param callbackContext The callback context.
 * @return A PluginResult representing the result of the provided action. A
 * status of INVALID_ACTION is returned if the action is not
 * recognized.
 */
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult result;

    if (ACTION_INITIALIZE.equals(action)) {
        result = initialize(callbackContext, args);
    } else if (ACTION_GET_INSTALLATION_ID.equals(action)) {
        result = getInstallationId(callbackContext);
    } else if (ACTION_GET_INSTALLATION_OBJECT_ID.equals(action)) {
        result = getInstallationObjectId(callbackContext);
    } else if (ACTION_GET_SUBSCRIPTIONS.equals(action)) {
        result = getSubscriptions(callbackContext);
    } else if (ACTION_SUBSCRIBE.equals(action)) {
        result = subscribe(args.getString(0), callbackContext);
    } else if (ACTION_UNSUBSCRIBE.equals(action)) {
        result = unsubscribe(args.getString(0), callbackContext);
    } else if (ACTION_GET_PENDING_PUSH.equals(action)) {
        result = getPendingPush(callbackContext);
    } else {
        result = new PluginResult(Status.INVALID_ACTION);
    }

    if (result != null)
        callbackContext.sendPluginResult(result);

    return true;
}

From source file:se.frostyelk.cordova.parse.plugin.ParsePlugin.java

private PluginResult initialize(final CallbackContext callbackContext, final JSONArray args) {
    try {/* w  ww  . ja  v a2 s  .c  om*/
        appId = args.getString(0);
        clientKey = args.getString(1);
        Parse.initialize(cordova.getActivity().getApplicationContext(), appId, clientKey);
        ParseInstallation.getCurrentInstallation().saveInBackground();
        ParseAnalytics.trackAppOpenedInBackground(cordova.getActivity().getIntent());
        callbackContext.success();
    } catch (JSONException e) {
        callbackContext.error("JSONException: " + e.getMessage());
    }

    return null;
}

From source file:com.hichinaschool.flashcards.libanki.Decks.java

public void load(String decks, String dconf) {
    mDecks = new HashMap<Long, JSONObject>();
    mDconf = new HashMap<Long, JSONObject>();
    try {//from  w  ww.j a v a  2s.c  om
        JSONObject decksarray = new JSONObject(decks);
        JSONArray ids = decksarray.names();
        for (int i = 0; i < ids.length(); i++) {
            String id = ids.getString(i);
            JSONObject o = decksarray.getJSONObject(id);
            long longId = Long.parseLong(id);
            mDecks.put(longId, o);
        }
        JSONObject confarray = new JSONObject(dconf);
        ids = confarray.names();
        for (int i = 0; i < ids.length(); i++) {
            String id = ids.getString(i);
            mDconf.put(Long.parseLong(id), confarray.getJSONObject(id));
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    mChanged = false;
}

From source file:com.wso2.mobile.mdm.DisplayDeviceInfoActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_display_device_info);
    DeviceInfo deviceInfo = new DeviceInfo(DisplayDeviceInfoActivity.this);
    TextView device_id = (TextView) findViewById(R.id.txtId);
    TextView device = (TextView) findViewById(R.id.txtDevice);
    TextView model = (TextView) findViewById(R.id.txtModel);
    TextView operator = (TextView) findViewById(R.id.txtOperator);
    TextView sdk = (TextView) findViewById(R.id.txtSDK);
    TextView os = (TextView) findViewById(R.id.txtOS);
    TextView root = (TextView) findViewById(R.id.txtRoot);

    device_id.setText(getResources().getString(R.string.info_label_imei) + " " + deviceInfo.getDeviceId());
    device.setText(getResources().getString(R.string.info_label_device) + " " + deviceInfo.getDevice());
    model.setText(getResources().getString(R.string.info_label_model) + " " + deviceInfo.getDeviceModel());
    JSONArray jsonArray = null;
    String operators = "";
    if (deviceInfo.getNetworkOperatorName() != null) {
        jsonArray = deviceInfo.getNetworkOperatorName();
    }//  w  w w. j ava  2 s .c o  m

    for (int i = 0; i < jsonArray.length(); i++) {
        try {
            if (jsonArray.getString(i) != null) {
                if (i == (jsonArray.length() - 1)) {
                    operators += jsonArray.getString(i);
                } else {
                    operators += jsonArray.getString(i) + ", ";
                }
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    if (operators.equals(null)) {
        operators = getResources().getString(R.string.info_label_no_sim);
    }
    operator.setText(getResources().getString(R.string.info_label_operator) + " " + operators);
    if (deviceInfo.getIMSINumber() != null) {
        sdk.setText(getResources().getString(R.string.info_label_imsi) + " " + deviceInfo.getIMSINumber());
    } else {
        sdk.setText(getResources().getString(R.string.info_label_imsi) + " " + operators);
    }
    os.setText(getResources().getString(R.string.info_label_os) + " " + deviceInfo.getOsVersion());
    root.setText(getResources().getString(R.string.info_label_rooted) + " "
            + (deviceInfo.isRooted() ? getResources().getString(R.string.info_label_rooted_answer_yes)
                    : getResources().getString(R.string.info_label_rooted_answer_no)));

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        if (extras.containsKey(getResources().getString(R.string.intent_extra_from_activity))) {
            FROM_ACTIVITY = extras.getString(getResources().getString(R.string.intent_extra_from_activity));
        }

        if (extras.containsKey(getResources().getString(R.string.intent_extra_regid))) {
            REG_ID = extras.getString(getResources().getString(R.string.intent_extra_regid));
        }
    }

}

From source file:org.chromium.ChromeFileSystem.java

private static String getIntentType(JSONArray mimeTypes) throws JSONException {
    String intentType = null;//from w  w w  .j a v a 2  s . c  o  m
    String intentTypePrefix = null;

    // Iterate through all the given mime types and determine the lowest common denominator.
    for (int i = 0; i < mimeTypes.length(); i++) {
        String mimeType = mimeTypes.getString(i);
        if (intentType == null) {
            intentType = mimeType;
            intentTypePrefix = intentType.substring(0, intentType.indexOf('/'));
        } else {
            if (!intentType.equals(mimeType)) {
                String mimeTypePrefix = mimeType.substring(0, mimeType.indexOf('/'));
                if (intentTypePrefix.equals(mimeTypePrefix)) {
                    // We've encountered two suffixes with the same prefix, so we allow <prefix>/*.
                    intentType = new StringBuilder(intentTypePrefix).append("/*").toString();
                } else {
                    // We've encountered two different prefixes, so we allow */*.
                    return "*/*";
                }
            }
        }
    }

    if (intentType == null) {
        return "*/*";
    }

    return intentType;
}

From source file:edu.umass.cs.msocket.common.policies.RandomProxyPolicy.java

@Override
public List<InetSocketAddress> getNewProxy() throws Exception {
    List<InetSocketAddress> result = new LinkedList<InetSocketAddress>();
    final GuidEntry guidEntry = gnsCredentials.getGuidEntry();

    // Lookup proxies in proxy group list
    UniversalGnsClient gnsClient = gnsCredentials.getGnsClient();
    String groupGuid = gnsClient.lookupGuid(proxyGroupName);
    JSONArray members = gnsClient.groupGetMembers(groupGuid, gnsCredentials.getGuidEntry());

    for (int i = 0; i < members.length(); i++) { // Add each proxy to the list
        String proxyGuid = members.getString(i);

        // Check first that this member is a proxy and not another service
        String serviceType = gnsClient.fieldRead(proxyGuid, GnsConstants.SERVICE_TYPE_FIELD, guidEntry)
                .getString(0);/*from  w w  w  .  j ava2  s.c o m*/
        if (!GnsConstants.PROXY_SERVICE.equals(serviceType))
            continue; // This is not a proxy, ignore

        // Grab the proxy IP address
        String proxyIp = gnsClient.fieldRead(proxyGuid, GnsConstants.PROXY_EXTERNAL_IP_FIELD, guidEntry)
                .getString(0);
        String[] parsed = proxyIp.split(":");
        InetSocketAddress addr = new InetSocketAddress(parsed[0], Integer.parseInt(parsed[1]));
        result.add(addr);

        // Did we get enough proxies?
        if (result.size() == numProxy)
            break;
    }

    return result;
}

From source file:com.jennifer.ui.util.scale.OrdinalScale.java

public double get(String x) {
    int index = -1;

    JSONArray domain = domain();

    for (int i = 0, len = domain.length(); i < len; i++) {
        if (x.equals(domain.getString(i))) {
            index = i;/*w w  w  .  j av  a2 s  .c  o m*/
            break;
        }
    }

    if (index > -1) {
        return range().getDouble(index);
    } else {
        return -1;
    }
}

From source file:com.miz.apis.trakt.Show.java

public Show(JSONObject summaryJson) {
    try {//w  w w  . j a  va2  s  .  com
        mTitle = summaryJson.getString("title");
        mYear = summaryJson.getInt("year");
        mUrl = summaryJson.getString("url");
        mFirstAired = summaryJson.getLong("first_aired");
        mCountry = summaryJson.getString("country");
        mOverview = summaryJson.getString("overview");
        mRuntime = summaryJson.getInt("runtime");
        mStatus = summaryJson.getString("status");
        mNetwork = summaryJson.getString("network");
        mAirDay = summaryJson.getString("air_day");
        mAirTime = summaryJson.getString("air_time");
        mCertification = summaryJson.getString("certification");
        mImdbId = summaryJson.getString("imdb_id");
        mTvdbId = summaryJson.getInt("tvdb_id");
        mTvRageId = summaryJson.getInt("tvrage_id");
        mPoster = summaryJson.getString("poster");
        mFanart = summaryJson.getJSONObject("images").getString("fanart");
        mRating = summaryJson.getJSONObject("ratings").getInt("percentage");

        JSONArray genres = summaryJson.getJSONArray("genres");
        for (int i = 0; i < genres.length(); i++)
            mGenres.add(genres.getString(i));

    } catch (JSONException e) {
    }
}

From source file:com.cranberrygame.cordova.plugin.ad.admob.Util.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    PluginResult result = null;//from ww  w  .  j  a  v a2  s.co  m

    //args.length()
    //args.getString(0)
    //args.getString(1)
    //args.getInt(0)
    //args.getInt(1)
    //args.getBoolean(0)
    //args.getBoolean(1)
    //JSONObject json = args.optJSONObject(0);
    //json.optString("adUnit")
    //json.optString("adUnitFullScreen")
    //JSONObject inJson = json.optJSONObject("inJson");

    if (action.equals("setUp")) {
        //Activity activity=cordova.getActivity();
        //webView
        //
        final String adUnit = args.getString(0);
        Log.d(LOG_TAG, adUnit);
        final String adUnitFullScreen = args.getString(1);
        Log.d(LOG_TAG, adUnitFullScreen);
        final boolean isOverlap = args.getBoolean(2);
        Log.d(LOG_TAG, isOverlap ? "true" : "false");
        final boolean isTest = args.getBoolean(3);
        Log.d(LOG_TAG, isTest ? "true" : "false");

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _setUp(adUnit, adUnitFullScreen, isOverlap, isTest);

                PluginResult pr = new PluginResult(PluginResult.Status.OK);
                //pr.setKeepCallback(true);
                delayedCC.sendPluginResult(pr);
                //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
                //pr.setKeepCallback(true);
                //delayedCC.sendPluginResult(pr);               
            }
        });

        return true;
    } else if (action.equals("preloadBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView

        bannerAdPreload = true;

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _preloadBannerAd();
            }
        });

        return true;
    } else if (action.equals("reloadBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _reloadBannerAd();
            }
        });

        return true;
    } else if (action.equals("showBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //
        final String position = args.getString(0);
        Log.d(LOG_TAG, position);
        final String size = args.getString(1);
        Log.d(LOG_TAG, size);

        //
        boolean bannerIsShowing = false;
        if (isOverlap) {
            if (bannerView != null) {
                //if banner is showing
                RelativeLayout bannerViewLayout = (RelativeLayout) bannerView.getParent();
                if (bannerViewLayout != null) {
                    bannerIsShowing = true;
                }
            }
        } else {
            if (bannerView != null) {
                //if banner is showing
                ViewGroup parentView = (ViewGroup) bannerView.getParent();
                if (parentView != null) {
                    bannerIsShowing = true;
                }
            }
        }
        if (bannerIsShowing && position.equals(this.position) && size.equals(this.size)) {
            PluginResult pr = new PluginResult(PluginResult.Status.OK);
            //pr.setKeepCallback(true);
            callbackContext.sendPluginResult(pr);
            //PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
            //pr.setKeepCallback(true);
            //callbackContext.sendPluginResult(pr);         

            return true;
        }

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _showBannerAd(position, size);
            }
        });

        return true;
    } else if (action.equals("hideBannerAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        bannerViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _hideBannerAd();
            }
        });

        return true;
    } else if (action.equals("preloadFullScreenAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        fullScreenAdPreload = true;

        interstitialViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _preloadFullScreenAd();
            }
        });

        return true;
    } else if (action.equals("reloadFullScreenAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        if (interstitialView == null) {
            //PluginResult pr = new PluginResult(PluginResult.Status.OK);
            //pr.setKeepCallback(true);
            //callbackContext.sendPluginResult(pr);
            PluginResult pr = new PluginResult(PluginResult.Status.ERROR);
            //pr.setKeepCallback(true);
            callbackContext.sendPluginResult(pr);

            return true;
        }

        fullScreenAdPreload = true;

        interstitialViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _reloadFullScreenAd();
            }
        });

        return true;
    } else if (action.equals("showFullScreenAd")) {
        //Activity activity=cordova.getActivity();
        //webView
        //

        interstitialViewCC = callbackContext;

        final CallbackContext delayedCC = callbackContext;
        cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                _showFullScreenAd();
            }
        });

        return true;
    }

    return false; // Returning false results in a "MethodNotFound" error.
}