Example usage for org.json JSONArray optString

List of usage examples for org.json JSONArray optString

Introduction

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

Prototype

public String optString(int index) 

Source Link

Document

Get the optional string value associated with an index.

Usage

From source file:com.commontime.plugin.notification.Notification.java

/**
 * Options from scheduled notification.//from   w  w  w.jav  a 2  s  .  com
 *
 * @param ids     Set of local notification IDs
 * @param command The callback context used when calling back into JavaScript.
 */
private void getSingleScheduled(JSONArray ids, CallbackContext command) {
    getOptions(ids.optString(0), NotificationWrapper.Type.SCHEDULED, command);
}

From source file:com.commontime.plugin.notification.Notification.java

/**
 * Options from triggered notification./*from   ww  w .  j ava 2s.  co  m*/
 *
 * @param ids     Set of local notification IDs
 * @param command The callback context used when calling back into JavaScript.
 */
private void getSingleTriggered(JSONArray ids, CallbackContext command) {
    getOptions(ids.optString(0), NotificationWrapper.Type.TRIGGERED, command);
}

From source file:org.catnut.service.UpgradeService.java

private void checkout() throws Exception {
    URL url = new URL(METADATA_URL);
    InputStream inputStream = url.openStream();
    Scanner in = new Scanner(inputStream).useDelimiter("\\A");
    if (in.hasNext()) {
        JSONObject metadata = new JSONObject(in.next());
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
        if (info.versionCode < metadata.optInt(FIELD_VERSION_CODE)) {
            Notification.InboxStyle style = new Notification.InboxStyle(mBuilder);
            String size = metadata.optString("size");
            style.setBigContentTitle(getString(R.string.find_new_version, size));
            JSONArray messages = metadata.optJSONArray("messages");
            for (int i = 0; i < messages.length(); i++) {
                style.addLine(messages.optString(i));
            }//  ww  w  . ja va 2s . c  o m
            // download&upgrade intent
            Intent download = new Intent(this, UpgradeService.class);
            download.setAction(ACTION_DOWNLOAD);
            download.putExtra(DOWNLOAD_LINK, metadata.optString(DOWNLOAD_LINK));
            PendingIntent piDownload = PendingIntent.getService(this, 0, download, 0);
            mBuilder.addAction(R.drawable.ic_stat_download_dark, getString(R.string.down_load_and_upgrade),
                    piDownload);
            // dismiss notification
            Intent dismiss = new Intent(this, UpgradeService.class);
            dismiss.setAction(ACTION_DISMISS);
            PendingIntent piDismiss = PendingIntent.getService(this, 0, dismiss, 0);
            mBuilder.addAction(R.drawable.ic_stat_content_remove_dark, getString(R.string.not_upgrade_now),
                    piDismiss);
            // show it.
            mBuilder.setTicker(getString(R.string.find_new_version));
            mNotificationManager.notify(ID, mBuilder.setDefaults(Notification.DEFAULT_ALL).build());
        } else {
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(UpgradeService.this, getString(R.string.already_updated), Toast.LENGTH_SHORT)
                            .show();
                }
            });
        }
    }
    in.close();
}

From source file:com.justone.android.main.MainActivity.java

/***
   * //from  ww  w  .j  a  v  a 2  s.  c  om
* @throws JSONException 
   */
public void checkVersion() throws JSONException {

    if (!Utils.isWifi(this))
        return;

    String versionInfo = this.dataOp.getUpdateVersionInfo();
    JSONObject jsonOb = new JSONObject(versionInfo);
    String viewData = jsonOb.getString("data");
    JSONArray jsonArray = new JSONArray(viewData);
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONArray tempJson = (JSONArray) jsonArray.opt(i);

        if (tempJson.optString(0).equals("version_id")) {
            JustOne.setServerVersion(tempJson.optInt(1));
        }
        if (tempJson.optString(0).equals("version_name"))
            JustOne.versionName = tempJson.optString(1);
        if (tempJson.optString(0).equals("version_desc"))
            JustOne.setVersionDesc(tempJson.optString(1));
        if (tempJson.optString(0).equals("download_href"))
            JustOne.download_href = tempJson.optString(1);
        /*ArrayList<String> tempArray = new ArrayList<String>();
                
        tempJson.getJSONArray(index)
        tempArray.add(String.valueOf(nameToIdMap(tempJson
          .getString(0))));
        tempArray.add(String.valueOf(tempJson.getString(1)));
        tempArray.add(String.valueOf(tempJson.getString(2)));
        tempResult.add(tempArray);*/
    }
    if (JustOne.getLocalVersion() < JustOne.getServerVersion()) {
        // 
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("").setMessage(JustOne.getVersionDesc())
                .setPositiveButton("", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent updateIntent = new Intent(MainActivity.this, UpdateService.class);
                        updateIntent.putExtra("app_name", getResources().getString(R.string.app_name));
                        startService(updateIntent);
                        dialog.dismiss();
                    }
                }).setNegativeButton("", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        alert.create().show();

    }
}

From source file:androidGLUESigner.helpers.SettingsHelper.java

/**
 * Gets the list of signed documents/*w  ww .java 2 s . c o m*/
 * @return a list of signed documents
 */
public ArrayList<String> getSignedDocList() {
    String docString = sharedPref.getString("signedDocs", null);
    ArrayList<String> urls = new ArrayList<String>();
    if (docString != null) {
        try {
            JSONArray a = new JSONArray(docString);
            for (int i = 0; i < a.length(); i++) {
                String url = a.optString(i);
                urls.add(url);
            }
        } catch (JSONException e) {
            Logger.toConsole(e);
        }
    }
    return urls;
}

From source file:edu.txstate.dmlab.clusteringwiki.rest.ClusterController.java

/**
 * Update paths for a given cluster edit
 * @param qid  Query id of the executed query
 * @param algo  Algorithm used for clustering
 * @param request  HttpServletRequest//  w w w . j a va 2  s  . c  o  m
 * @param response  HttpServletResponse
 * @param model  Model
 * @throws Exception
 */
@RequestMapping("/clusterUpdate/{queryId}/{clusteringAlgo}")
public void savePaths(@PathVariable("queryId") String qid, @PathVariable("clusteringAlgo") String algo,
        HttpServletRequest request, HttpServletResponse response, Model model) throws Exception {

    try {

        Integer queryId = Integer.valueOf(_cleanExtensions(qid));
        Integer clusteringAlgo = Integer.valueOf(_cleanExtensions(algo));

        String data = null;
        InputStream is = request.getInputStream();

        if (is != null) {
            try {
                StringBuilder sb = new StringBuilder();
                String line;
                BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                while ((line = reader.readLine()) != null) {
                    sb.append(line);
                }
                data = sb.toString();
            } finally {
                is.close();
            }

        }

        if (data == null) {
            sendOutput(response, "{\"error\":\"No data received.\"}");
            return;
        }

        JSONArray paths = new JSONArray(data);

        for (int i = 0; i < paths.length(); i++) {
            JSONObject j = paths.getJSONObject(i);
            Integer cardinality = j.getInt("cardinality");
            JSONArray path = j.getJSONArray("lPath");

            clusterEditDao.updatePath(queryId, clusteringAlgo, path.optString(1).trim(),
                    path.optString(2).trim(), path.optString(3).trim(), path.optString(4).trim(),
                    path.optString(5).trim(), cardinality);
        }

        sendOutput(response, "{\"success\":true}");

    } catch (Exception e) {
        sendOutput(response, "{\"error\":" + JSONObject.quote(e.getMessage()) + "}");
        return;
    }
}

From source file:com.basho.riak.client.http.util.ClientUtils.java

/**
 * Convert a {@link JSONArray} to a list
 * //  www . ja  va2  s  . c  o m
 * @param json
 *            {@link JSONArray} to convert
 * @return List of string representations of the elements
 */
public static List<String> jsonArrayAsList(JSONArray json) {
    if (json == null)
        return null;

    List<String> l = new ArrayList<String>();
    for (int i = 0; i < json.length(); i++) {
        l.add(json.optString(i));
    }
    return l;
}

From source file:edu.asu.bscs.csiebler.waypointapplication.WaypointServerStub.java

/**
 *
 * @return//from   w w w  .java 2 s  .co m
 */
public String[] getNames() {
    String[] result = null;
    try {
        String jsonStr = this.packageWaypointCall("getNames", null, null);
        debug("sending: " + jsonStr);
        String resString = server.call(jsonStr);
        debug("got back: " + resString);
        JSONObject res = new JSONObject(resString);
        String resArrStr = res.optString("result");
        JSONArray nameArr = new JSONArray(resArrStr);
        Vector<String> vec = new Vector<>();

        for (int i = 0; i < nameArr.length(); i++) {
            vec.add(nameArr.optString(i));
        }

        result = vec.toArray(new String[] {});
    } catch (Exception ex) {
        System.out.println("exception in rpc call to getNames: " + ex.getMessage());
    }

    return result;
}

From source file:edu.asu.bscs.csiebler.waypointapplication.WaypointServerStub.java

/**
 *
 * @param category//from  www. j av a 2 s .  c o  m
 * @return
 */
public String[] getNamesInCategory(String category) {
    String[] result = null;

    try {
        String jsonStr = this.packageWaypointCall("getNamesInCategory", category, null);
        debug("sending: " + jsonStr);
        String resString = server.call(jsonStr);
        debug("got back: " + resString);
        JSONObject res = new JSONObject(resString);
        String resArrStr = res.optString("result");
        JSONArray nameArr = new JSONArray(resArrStr);
        Vector<String> vec = new Vector<>();

        for (int i = 0; i < nameArr.length(); i++) {
            vec.add(nameArr.optString(i));
        }

        result = vec.toArray(new String[] {});
    } catch (Exception ex) {
        System.out.println("exception in rpc call to getNamesInCategory: " + ex.getMessage());
    }

    return result;
}

From source file:edu.asu.bscs.csiebler.waypointapplication.WaypointServerStub.java

/**
 *
 * @return//from   w  w w .j  av a 2s. co m
 */
public String[] getCategoryNames() {
    String[] result = null;

    try {
        String jsonStr = this.packageWaypointCall("getCategoryNames", null, null);
        debug("sending: " + jsonStr);
        String resString = server.call(jsonStr);
        debug("got back: " + resString);
        JSONObject res = new JSONObject(resString);
        String resArrStr = res.optString("result");
        JSONArray nameArr = new JSONArray(resArrStr);
        Vector<String> vec = new Vector<>();

        for (int i = 0; i < nameArr.length(); i++) {
            vec.add(nameArr.optString(i));
        }

        result = vec.toArray(new String[] {});
    } catch (Exception ex) {
        System.out.println("exception in rpc call to getCategoryNames: " + ex.getMessage());
    }

    return result;
}