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:cn.ttyhuo.activity.InfoOwnerActivity.java

protected void setupViewOfHasLogin(JSONObject jObject) {
    try {/*w  w w.jav a2s .c  om*/

        ArrayList<String> pics = new ArrayList<String>();
        JSONArray jsonArray = jObject.optJSONArray("imageList");
        if (jsonArray != null) {
            for (int s = 0; s < jsonArray.length(); s++)
                pics.add(jsonArray.getString(s));
        }
        while (pics.size() < 3)
            pics.add("plus");
        mPicData = pics;
        mPicAdapter.updateData(pics);

        if (jObject.getBoolean("isTruckVerified")) {
            tv_edit_tips.setText("?????");
        } else if (jsonArray != null && jsonArray.length() > 2 && jObject.has("truckInfo")) {
            tv_edit_tips.setText(
                    "?????????");
        } else {
            tv_edit_tips.setText("??????");
        }

        if (jObject.has("truckInfo")) {
            JSONObject userJsonObj = jObject.getJSONObject("truckInfo");
            if (!userJsonObj.optString("licensePlate").isEmpty()
                    && userJsonObj.optString("licensePlate") != "null")
                mEditChepai.setText(userJsonObj.getString("licensePlate"));
            Integer truckType = userJsonObj.getInt("truckType");
            if (truckType != null && truckType > 0)
                mEditChexing.setText(ConstHolder.TruckTypeItems[truckType - 1]);
            else
                mEditChexing.setText("");
            if (!userJsonObj.optString("loadLimit").isEmpty() && userJsonObj.optString("loadLimit") != "null")
                mEditZaizhong.setText(userJsonObj.getString("loadLimit"));
            if (!userJsonObj.optString("truckLength").isEmpty()
                    && userJsonObj.optString("truckLength") != "null")
                mEditChechang.setText(userJsonObj.getString("truckLength"));
            if (!userJsonObj.optString("modelNumber").isEmpty()
                    && userJsonObj.optString("modelNumber") != "null")
                mEditXinghao.setText(userJsonObj.getString("modelNumber"));

            if (!userJsonObj.optString("seatingCapacity").isEmpty()
                    && userJsonObj.optString("seatingCapacity") != "null")
                mEditZuowei.setText(userJsonObj.getString("seatingCapacity"));
            if (!userJsonObj.optString("releaseYear").isEmpty()
                    && userJsonObj.optString("releaseYear") != "null")
                mEditDate.setText(userJsonObj.getString("releaseYear") + "");
            if (!userJsonObj.optString("truckWidth").isEmpty() && userJsonObj.optString("truckWidth") != "null")
                mEditKuan.setText(userJsonObj.getString("truckWidth"));
            if (!userJsonObj.optString("truckHeight").isEmpty()
                    && userJsonObj.optString("truckHeight") != "null")
                mEditGao.setText(userJsonObj.getString("truckHeight"));
        }

        if (!jObject.getBoolean("isTruckVerified")) {
            mEditChexing.setOnClickListener(this);
            mEditDate.setOnClickListener(this);
            mEditChepai.setFocusable(true);
            mEditChepai.setEnabled(true);
            mEditZaizhong.setFocusable(true);
            mEditZaizhong.setEnabled(true);
            mEditChechang.setFocusable(true);
            mEditChechang.setEnabled(true);
            mEditZuowei.setFocusable(true);
            mEditZuowei.setEnabled(true);
            mEditKuan.setFocusable(true);
            mEditKuan.setEnabled(true);
            mEditGao.setFocusable(true);
            mEditGao.setEnabled(true);
            mEditXinghao.setFocusable(true);
            mEditXinghao.setEnabled(true);
            canUpdate = true;
        } else {
            mPicGrid.setOnItemLongClickListener(null);

            mEditChepai.setFocusable(false);
            mEditChepai.setEnabled(false);
            mEditZaizhong.setFocusable(false);
            mEditZaizhong.setEnabled(false);
            mEditChechang.setFocusable(false);
            mEditChechang.setEnabled(false);
            mEditZuowei.setFocusable(false);
            mEditZuowei.setEnabled(false);
            mEditKuan.setFocusable(false);
            mEditKuan.setEnabled(false);
            mEditGao.setFocusable(false);
            mEditGao.setEnabled(false);
            mEditXinghao.setFocusable(false);
            mEditXinghao.setEnabled(false);
            canUpdate = false;
        }

        saveParams(true);

    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.jennifer.ui.chart.grid.DateGrid.java

public void drawBefore() {
    initDomain();/*  w  ww. j  av  a  2 s . c  om*/

    int max = chart.area("height");

    if (orient == Orient.TOP || orient == Orient.BOTTOM) {
        max = chart.area("width");
    }

    JSONArray range = (JSONArray) new JSONArray().put(0).put(max);

    TimeScale timeScale = (TimeScale) this.scale;

    timeScale.domain(options.getJSONArray("domain")).rangeRound(range);

    boolean realtime = options.optBoolean("realtime", false);
    JSONArray step = JSONUtil.clone(options.getJSONArray("step"));

    if (realtime) {
        this.ticks = timeScale.realTicks(step.getString(0), step.getInt(1));
    } else {
        this.ticks = timeScale.ticks(step.getString(0), step.getInt(1));
    }

    // step = [this.time.days, 1];
    this.bar = 6;

    this.values = new JSONArray();

    for (int i = 0, len = this.ticks.length(); i < len; i++) {
        this.values.put(this.scale.get(this.ticks.getDouble(i)));
    }
}

From source file:com.jennifer.ui.chart.grid.DateGrid.java

private void initDomain() {

    if (has("target") && !has("domain")) {

        if (options.get("target") instanceof String) {
            JSONArray list = new JSONArray();
            list.put(options.getString("target"));
            options.put("target", list);
        }/*from  w w  w.  j a v  a  2 s.com*/

        JSONArray target = (JSONArray) options.getJSONArray("target");
        JSONArray domain = new JSONArray();
        JSONArray data = chart.data();

        long min = 0;
        long max = 0;

        boolean hasMin = options.has("min");
        boolean hasMax = options.has("max");

        for (int i = 0, len = target.length(); i < len; i++) {
            String key = target.getString(i);

            for (int index = 0, dataLength = data.length(); index < dataLength; index++) {
                JSONObject row = data.getJSONObject(index);

                long value = 0;

                if (row.get(key) instanceof Date) {
                    value = ((Date) row.get(key)).getTime();
                } else {
                    value = row.getLong(key);
                }

                if (!hasMin) {
                    min = value;
                    hasMin = true;
                } else if (min > value)
                    min = value;

                if (!hasMax) {
                    max = value;
                    hasMax = true;
                } else if (max < value)
                    max = value;
            }

        }

        options.put("max", max);
        options.put("min", min);

        domain.put(min).put(max);

        if (options.optBoolean("reverse", false)) {
            JSONUtil.reverse(domain);
        }

        options.put("domain", domain);

    }

}

From source file:net.zorgblub.typhon.dto.PageOffsets.java

private static List<List<Integer>> readOffsets(JSONArray jsonArray) throws JSONException {

    List<List<Integer>> result = new ArrayList<List<Integer>>();

    for (int i = 0; i < jsonArray.length(); i++) {
        List<Integer> sublist = new ArrayList<>();

        JSONArray subArray = new JSONArray(jsonArray.getString(i));

        for (int j = 0; j < subArray.length(); j++) {
            int val = subArray.getInt(j);
            sublist.add(val);
        }//from  w w w . j  a  va2  s .c  o  m

        result.add(sublist);
    }

    return result;
}

From source file:mr.robotto.engine.loader.components.skeleton.MrSkeletonLoader.java

private ArrayList<String> loadBoneOrder() throws JSONException {
    JSONArray boneOrderJson = mRoot.getJSONArray("BoneOrder");
    ArrayList<String> boneOrder = new ArrayList<>();
    for (int i = 0; i < boneOrderJson.length(); i++) {
        String name = boneOrderJson.getString(i);
        boneOrder.add(name);//from w  ww  .  ja  v  a  2  s. c o  m
    }
    return boneOrder;
}

From source file:com.intel.xdk.file.File.java

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("uploadToServer")) {

        String localURL = args.getString(0);
        String uploadURL = args.getString(1);
        String folderName = args.getString(2);
        String mimeType = args.getString(3);
        String uploadProgressCallback = args.getString(4);

        this.uploadToServer(localURL, uploadURL, folderName, mimeType, uploadProgressCallback);
    } else if (action.equals("cancelUpload")) {
        this.cancelUpload();
    } else {//from  ww w .  jav  a2  s  .com
        return false;
    }
    return true;
}

From source file:com.phonegap.plugin.ChildBrowser.java

/**
 * Executes the request and returns PluginResult.
 *
 * @param action        The action to execute.
 * @param args          JSONArry of arguments for the plugin.
 * @param callbackId    The callback id used when calling back into JavaScript.
 * @return              A PluginResult object with a status and message.
 *//*from w w w .j a  v  a2  s  .  c o  m*/
public PluginResult execute(String action, JSONArray args, String callbackId) {
    PluginResult.Status status = PluginResult.Status.OK;
    String result = "";

    try {
        if (action.equals("showWebPage")) {
            this.browserCallbackId = callbackId;

            // If the ChildBrowser is already open then throw an error
            if (dialog != null && dialog.isShowing()) {
                return new PluginResult(PluginResult.Status.ERROR, "ChildBrowser is already open");
            }

            result = this.showWebPage(args.getString(0), args.optJSONObject(1));

            if (result.length() > 0) {
                status = PluginResult.Status.ERROR;
                return new PluginResult(status, result);
            } else {
                PluginResult pluginResult = new PluginResult(status, result);
                pluginResult.setKeepCallback(true);
                return pluginResult;
            }
        } else if (action.equals("close")) {
            closeDialog();

            JSONObject obj = new JSONObject();
            obj.put("type", CLOSE_EVENT);

            PluginResult pluginResult = new PluginResult(status, obj);
            pluginResult.setKeepCallback(false);
            return pluginResult;
        } else if (action.equals("openExternal")) {
            result = this.openExternal(args.getString(0), args.optBoolean(1));
            if (result.length() > 0) {
                status = PluginResult.Status.ERROR;
            }
        } else {
            status = PluginResult.Status.INVALID_ACTION;
        }
        return new PluginResult(status, result);
    } catch (JSONException e) {
        return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
    }
}

From source file:com.macadamian.blinkup.BlinkUpPlugin.java

private boolean startBlinkUp(final Activity activity, final BlinkupController controller, JSONArray data) {
    int timeoutMs;
    try {/*from  w  w w  .ja v  a2s .c  o  m*/
        mApiKey = data.getString(START_BLINKUP_ARG_API_KEY);
        mDeveloperPlanId = data.getString(START_BLINKUP_ARG_DEVELOPER_PLAN_ID);
        mIsInDevelopment = data.getBoolean(START_BLINKUP_IS_IN_DEVELOPMENT);
        timeoutMs = data.getInt(START_BLINKUP_ARG_TIMEOUT_MS);
    } catch (JSONException exc) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_ARGUMENTS);
        return false;
    }

    // if api key not valid, send error message and quit
    if (!apiKeyFormatValid()) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_API_KEY);
        return false;
    } else if (mDeveloperPlanId == null || mDeveloperPlanId.isEmpty()) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_ARGUMENTS);
        return false;
    }

    controller.intentBlinkupComplete = createBlinkUpCompleteIntent(activity, timeoutMs);

    // default is to run on WebCore thread, we have UI so need UI thread
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            presentBlinkUp(activity, controller);
        }
    });
    return true;
}

From source file:com.macadamian.blinkup.BlinkUpPlugin.java

/**
 * Old Style of BlinkUp invocation./*w  ww .  j  a  v a 2s . c  o m*/
 *
 * @deprecated use {@link #startBlinkUp()} instead.
 */
@Deprecated
private boolean invokeBlinkup(final Activity activity, final BlinkupController controller, JSONArray data) {
    int timeoutMs;
    try {
        mApiKey = data.getString(INVOKE_BLINKUP_ARG_API_KEY);
        mDeveloperPlanId = data.getString(INVOKE_BLINKUP_ARG_DEVELOPER_PLAN_ID);
        timeoutMs = data.getInt(INVOKE_BLINKUP_ARG_TIMEOUT_MS);
        mGeneratePlanId = data.getBoolean(INVOKE_BLINKUP_ARG_GENERATE_PLAN_ID);
    } catch (JSONException exc) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_ARGUMENTS);
        return false;
    }

    // if api key not valid, send error message and quit
    if (!apiKeyFormatValid()) {
        BlinkUpPluginResult.sendPluginErrorToCallback(ERROR_INVALID_API_KEY);
        return false;
    }

    controller.intentBlinkupComplete = createBlinkUpCompleteIntent(activity, timeoutMs);

    // default is to run on WebCore thread, we have UI so need UI thread
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            presentBlinkUp(activity, controller);
        }
    });
    return true;
}

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

private List<Contact> getContacts(final String url) throws Exception {
    Response serviceResponse;// ww w. ja va 2s  .  c  o  m
    try {
        serviceResponse = authenticationStrategy.executeFeed(url);
    } catch (Exception e) {
        throw new SocialAuthException("Error while getting contacts from " + url, e);
    }
    if (serviceResponse.getStatus() != 200) {
        throw new SocialAuthException(
                "Error while getting contacts from " + url + "Status : " + serviceResponse.getStatus());
    }
    String result;
    try {
        result = serviceResponse.getResponseBodyAsString(Constants.ENCODING);
    } catch (Exception e) {
        throw new ServerDataException("Failed to get response from " + url, e);
    }
    LOG.debug("User Contacts list in JSON " + result);
    JSONObject resp = new JSONObject(result);
    List<Contact> plist = new ArrayList<Contact>();
    if (resp.has("data")) {
        JSONArray addArr = resp.getJSONArray("data");
        LOG.debug("Contacts Found : " + addArr.length());
        for (int i = 0; i < addArr.length(); i++) {
            JSONObject obj = addArr.getJSONObject(i);
            Contact p = new Contact();
            if (obj.has("email_hashes")) {
                JSONArray emailArr = obj.getJSONArray("email_hashes");
                if (emailArr.length() > 0) {
                    p.setEmailHash(emailArr.getString(0));
                }
            }
            if (obj.has("name")) {
                p.setDisplayName(obj.getString("name"));
            }
            if (obj.has("first_name")) {
                p.setFirstName(obj.getString("first_name"));
            }
            if (obj.has("last_name")) {
                p.setLastName(obj.getString("last_name"));
            }
            if (obj.has("id")) {
                p.setId(obj.getString("id"));
            }
            plist.add(p);
        }
    }
    serviceResponse.close();
    return plist;
}