List of usage examples for org.json JSONArray optInt
public int optInt(int index)
From source file:com.samsung.richnotification.RichNotificationOptions.java
RichNotificationOptions(JSONArray data) throws JSONException { // Fetch options from the data object this.uuid = data.optString(0); this.readoutTitle = data.optString(1); this.readout = data.optString(2); this.notificationTitle = data.optString(3); this.headerSizeType = data.optString(4); this.primarySubHeader = data.optString(5); this.primaryBody = data.optString(6); this.qrImage = data.optString(7); this.primaryBackgroundColor = data.optString(8); this.primaryBackgroundImage = data.optString(9); this.secondaryType = data.optString(10); this.secondarySubHeader = data.optString(11); this.secondaryContent = data.optJSONArray(12); this.secondaryBackgroundColor = data.optString(13); this.secondaryImage = data.optString(14); this.secondaryIcon1Path = data.optString(15); this.secondaryIcon1Text = data.optString(16); this.secondaryIcon2Path = data.optString(17); this.secondaryIcon2Text = data.optString(18); this.notificationIcon = data.optString(19); int alert = data.optInt(20); int popup = data.optInt(21); this.actions = data.optJSONArray(22); switch (alert) { case RichNotificationHelper.ALERT_TYPE_SILENCE: this.alertType = AlertType.SILENCE; break;//from ww w. ja v a2 s . c o m case RichNotificationHelper.ALERT_TYPE_SOUND: this.alertType = AlertType.SOUND; break; case RichNotificationHelper.ALERT_TYPE_SOUND_AND_VIBR: this.alertType = AlertType.SOUND_AND_VIBRATION; break; case RichNotificationHelper.ALERT_TYPE_VIBR: this.alertType = AlertType.VIBRATION; break; default: this.alertType = AlertType.SOUND_AND_VIBRATION; } if (popup == RichNotificationHelper.POPUP_TYPE_NONE) this.popupType = PopupType.NONE; else this.popupType = PopupType.NORMAL; }
From source file:com.facebook.internal.FacebookRequestErrorClassification.java
private static Map<Integer, Set<Integer>> parseJSONDefinition(JSONObject definition) { JSONArray itemsArray = definition.optJSONArray("items"); if (itemsArray.length() == 0) { return null; }/*ww w . jav a 2 s. c o m*/ Map<Integer, Set<Integer>> items = new HashMap<>(); for (int i = 0; i < itemsArray.length(); i++) { JSONObject item = itemsArray.optJSONObject(i); if (item == null) { continue; } int code = item.optInt("code"); if (code == 0) { continue; } Set<Integer> subcodes = null; JSONArray subcodesArray = item.optJSONArray("subcodes"); if (subcodesArray != null && subcodesArray.length() > 0) { subcodes = new HashSet<>(); for (int j = 0; j < subcodesArray.length(); j++) { int subCode = subcodesArray.optInt(j); if (subCode != 0) { subcodes.add(subCode); } } } items.put(code, subcodes); } return items; }
From source file:com.vk.sdkweb.api.model.VKApiChat.java
/** * Fills a Chat instance from JSONObject. *///from w w w . ja v a 2 s .c om public VKApiChat parse(JSONObject source) { id = source.optInt("id"); type = source.optString("type"); title = source.optString("title"); admin_id = source.optInt("admin_id"); JSONArray users = source.optJSONArray("users"); if (users != null) { this.users = new int[users.length()]; for (int i = 0; i < this.users.length; i++) { this.users[i] = users.optInt(i); } } return this; }
From source file:org.catnut.plugin.zhihu.Zhihu.java
@Override public ContentValues convert(JSONArray array) { long now = System.currentTimeMillis(); ContentValues item = new ContentValues(); // ??item???//from w w w.ja v a2s . co m item.put(BaseColumns._ID, now); // item.put(STATUS, array.optString(1)); item.put(ANSWER, array.optString(2)); item.put(LAST_ALTER_DATE, array.optLong(4) * 1000); item.put(ANSWER_ID, array.optLong(5)); // JSONArray user = array.optJSONArray(6); if (user != null) { item.put(NICK, user.optString(0)); item.put(UID, user.optString(1)); item.put(AVATAR, user.optInt(2)); } // JSONArray question = array.optJSONArray(7); if (question != null) { item.put(TITLE, question.optString(1, null)); item.put(DESCRIPTION, question.optString(2)); item.put(QUESTION_ID, question.optLong(3)); } return item; }
From source file:org.bd2kccc.bd2kcccpubmed.Crawler.java
public static void main(String[] args) { HashMap<Integer, ArrayList<String>> publications = new HashMap(); for (int i = 0; i < BD2K_CENTERS.length; i++) { String searchUrl = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=" + BD2K_GRANTS[i] + "[Grant%20Number]&retmode=json&retmax=1000"; System.out.println(searchUrl); HttpRequest request = HttpRequest.get(searchUrl); JSONObject req = new JSONObject(request.body()); JSONArray idlist = req.getJSONObject("esearchresult").getJSONArray("idlist"); System.out.println(BD2K_CENTERS[i] + ": " + idlist.length()); for (int j = 0; j < idlist.length(); j++) { int pmid = idlist.optInt(j); if (!publications.containsKey(pmid)) { ArrayList<String> centerList = new ArrayList(); centerList.add(BD2K_CENTERS[i]); publications.put(pmid, centerList); } else { publications.get(pmid).add(BD2K_CENTERS[i]); }//ww w .j a v a 2 s .c om } } Integer[] pmids = publications.keySet().toArray(new Integer[0]); int collaborations = 0; for (int i = 0; i < pmids.length; i++) if (publications.get(pmids[i]).size() > 1) collaborations++; System.out.println(pmids.length + " publications found."); System.out.println(collaborations + " BD2K Center collaborations found."); String summaryUrl = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&retmode=json&rettype=abstract&id=" + pmids[0]; for (int i = 1; i < pmids.length; i++) summaryUrl += "," + pmids[i]; System.out.println(summaryUrl); HttpRequest request = HttpRequest.get(summaryUrl); JSONObject result = new JSONObject(request.body()).getJSONObject("result"); ArrayList<Publication> publicationStructs = new ArrayList(); for (int i = 0; i < pmids.length; i++) { JSONObject pub = result.getJSONObject("" + pmids[i]); Publication publication = new Publication(); publication.pmid = pmids[i]; publication.centers = publications.get(pmids[i]); publication.name = pub.optString("title", "NO_TITLE"); //remove <i> and </i> //replace &amp; with & publication.name = unescapeHtml4(publication.name); publication.date = pub.optString("sortpubdate", "1066/01/01 00:00").substring(0, 10); publication.date = publication.date.replaceAll("/", "-"); JSONArray articleIDs = pub.getJSONArray("articleids"); for (int j = 0; j < articleIDs.length(); j++) { JSONObject id = articleIDs.optJSONObject(j); if (id.optString("idtype").equals("doi")) publication.doi = id.optString("value"); } String issue = pub.optString("issue"); if (!issue.isEmpty()) issue = "(" + issue + ")"; publication.citation = pub.optString("source") + ". " + pub.optString("pubdate") + ";" + pub.optString("volume") + issue + ":" + pub.optString("pages") + "."; publication.authors = new ArrayList(); JSONArray aut = pub.getJSONArray("authors"); for (int j = 0; j < aut.length(); j++) { publication.authors.add(aut.getJSONObject(j).optString("name")); } publicationStructs.add(publication); } Collections.sort(publicationStructs); for (Publication p : publicationStructs) { if (p.isTool()) System.out.println(p.name); } JSONArray outputData = new JSONArray(); for (Publication p : publicationStructs) { JSONArray row = new JSONArray(); row.put(0, p.getName()); row.put(1, p.getType()); row.put(2, p.getDate()); row.put(3, p.getCenter()); row.put(4, p.getInitiative()); row.put(5, p.getDescription()); outputData.put(row); } System.out.println(outputData.toString(1)); }
From source file:com.commontime.plugin.notification.Notification.java
/** * Executes the request.//from www . j a v a 2 s .co m * <p/> * This method is called from the WebView thread. To do a non-trivial * amount of work, use: * cordova.getThreadPool().execute(runnable); * <p/> * To run on the UI thread, use: * cordova.getActivity().runOnUiThread(runnable); * * @param action The action to execute. * @param args The exec() arguments in JSON form. * @param command The callback context used when calling back into JavaScript. * @return Whether the action was valid. */ @Override public boolean execute(final String action, final JSONArray args, final CallbackContext command) throws JSONException { NotificationWrapper.setDefaultTriggerReceiver(TriggerReceiver.class); cordova.getThreadPool().execute(new Runnable() { public void run() { if (action.equals("schedule")) { schedule(args); command.success(); } else if (action.equals("update")) { update(args); command.success(); } else if (action.equals("cancel")) { cancel(args); command.success(); } else if (action.equals("cancelAll")) { cancelAll(); command.success(); } else if (action.equals("clear")) { clear(args); command.success(); } else if (action.equals("clearAll")) { clearAll(); command.success(); } else if (action.equals("isPresent")) { isPresent(args.optInt(0), command); } else if (action.equals("isScheduled")) { isScheduled(args.optInt(0), command); } else if (action.equals("isTriggered")) { isTriggered(args.optInt(0), command); } else if (action.equals("getAllIds")) { getAllIds(command); } else if (action.equals("getScheduledIds")) { getScheduledIds(command); } else if (action.equals("getTriggeredIds")) { getTriggeredIds(command); } else if (action.equals("getSingle")) { getSingle(args, command); } else if (action.equals("getSingleScheduled")) { getSingleScheduled(args, command); } else if (action.equals("getSingleTriggered")) { getSingleTriggered(args, command); } else if (action.equals("getAll")) { getAll(args, command); } else if (action.equals("getScheduled")) { getScheduled(args, command); } else if (action.equals("getTriggered")) { getTriggered(args, command); } else if (action.equals("registerForPush")) { registerForPush(args, command); } else if (action.equals("unregisterForPush")) { unregisterForPush(command); } else if (action.equals("deviceready")) { deviceready(); } } }); return true; }
From source file:com.commontime.plugin.notification.Notification.java
/** * Convert JSON array of integers to List. * * @param ary/* ww w . jav a 2 s.c o m*/ * Array of integers */ private List<Integer> toList(JSONArray ary) { ArrayList<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < ary.length(); i++) { list.add(ary.optInt(i)); } return list; }
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
@Override public void cancelNotifications_(JSONArray notificationIds) { Log.d(C.TAG, "LocalNotificationsBackend.cancelNotifications_: "); Editor editor = mPrefs.edit();/*ww w .ja va 2 s. c o m*/ AlarmManager am = (AlarmManager) mContext.getSystemService(Service.ALARM_SERVICE); NotificationManager nm = (NotificationManager) mContext.getSystemService(Service.NOTIFICATION_SERVICE); for (int i = 0, max = notificationIds.length(); i < max; i++) { int id = notificationIds.optInt(i); String idString = Integer.toString(id); PendingIntent pendingIntent = createPendingIntentForSchedule(idString); am.cancel(pendingIntent); nm.cancel(NOTIFICATION_MASK | id); String key = PREFS_PREFIX + idString; editor.remove(key); } editor.commit(); }
From source file:com.justone.android.main.MainActivity.java
/*** * /*from ww w . ja v a 2 s. c o m*/ * @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:com.vk.sdkweb.api.model.ParseUtils.java
/** * Parse int array from JSONObject with given name. * * @param from int JSON array like this one {@code {11, 34, 42}} *//*from w w w . ja va 2 s.co m*/ public static int[] parseIntArray(JSONArray from) { int[] result = new int[from.length()]; for (int i = 0; i < result.length; i++) { result[i] = from.optInt(i); } return result; }