List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:com.phonegap.AudioHandler.java
/** * Executes the request and returns PluginResult. * //www.j a v a2s . c om * @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. */ public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { if (action.equals("startRecordingAudio")) { this.startRecordingAudio(args.getString(0), args.getString(1)); } else if (action.equals("stopRecordingAudio")) { this.stopRecordingAudio(args.getString(0)); } else if (action.equals("startPlayingAudio")) { this.startPlayingAudio(args.getString(0), args.getString(1)); } else if (action.equals("pausePlayingAudio")) { this.pausePlayingAudio(args.getString(0)); } else if (action.equals("stopPlayingAudio")) { this.stopPlayingAudio(args.getString(0)); } else if (action.equals("getCurrentPositionAudio")) { long l = this.getCurrentPositionAudio(args.getString(0)); return new PluginResult(status, l); } else if (action.equals("getDurationAudio")) { long l = this.getDurationAudio(args.getString(0), args.getString(1)); return new PluginResult(status, l); } else if (action.equals("release")) { boolean b = this.release(args.getString(0)); return new PluginResult(status, b); } return new PluginResult(status, result); } catch (JSONException e) { e.printStackTrace(); return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:de.damdi.fitness.activity.settings.sync.WgerJSONParser.java
/** * Constructor. Will start download immediately. * // www.ja v a2 s. com * @param exerciseJSONString * The exercises as JSON-String * @param languageJSONString * The languages as JSON-String * @param muscleJSONString * The muscles as JSON-String * @param dataProvider * @throws JSONException */ public WgerJSONParser(String exerciseJSONString, String languageJSONString, String muscleJSONString, String equipmentJSONString, IDataProvider dataProvider) throws JSONException { mDataProvider = dataProvider; // parse languages SparseArray<Locale> localeSparseArray = parseLanguages(languageJSONString); // parse muscles SparseArray<Muscle> muscleSparseArray = parseMuscles(muscleJSONString); // parse equipment (not required until REST-API supports this) // SparseArray<SportsEquipment> equipmentSparseArray = parseEquipment(equipmentJSONString); JSONObject mainObject = new JSONObject(exerciseJSONString); Log.d(TAG, mainObject.toString()); JSONArray exerciseArray = mainObject.getJSONArray("objects"); // parse each exercise of the JSON Array for (int i = 0; i < exerciseArray.length(); i++) { JSONObject jsonExercise = exerciseArray.getJSONObject(i); // get name and check if exercise already exists String name = jsonExercise.getString("name"); if (dataProvider.exerciseExists(name)) continue; ExerciseType.Builder builder = new ExerciseType.Builder(name); // category (unused) // String category = jsonExercise.getString("category"); // comments (unused) // JSONArray commentArray = jsonExercise.getJSONArray("comments"); // for (int k = 0; k < commentArray.length(); k++) { // String comment = commentArray.getString(k); //} // description String description = jsonExercise.getString("description"); builder.description(description); // id (unused) //String id = jsonExercise.getString("id"); // language // the json-language String might look like this: // '/api/v1/language/1/' // only the number at the end is required String language = jsonExercise.getString("language"); int languageNumber = getLastNumberOfJson(language); Map<Locale, String> translationMap = new HashMap<Locale, String>(); translationMap.put(localeSparseArray.get(languageNumber), name); builder.translationMap(translationMap); // resource_uri (unused) //String resource_uri = jsonExercise.getString("resource_uri"); // muscles SortedSet<Muscle> muscleSet = new TreeSet<Muscle>(); JSONArray muscleArray = jsonExercise.getJSONArray("muscles"); for (int l = 0; l < muscleArray.length(); l++) { String muscleString = muscleArray.getString(l); Muscle muscle = muscleSparseArray.get(getLastNumberOfJson(muscleString)); muscleSet.add(muscle); } builder.activatedMuscles(muscleSet); // equipment // not yet supported by REST-API /*SortedSet<SportsEquipment> equipmentSet = new TreeSet<SportsEquipment>(); JSONArray equipmentArray = jsonExercise.getJSONArray("equipment"); for (int l = 0; l < equipmentArray.length(); l++) { String equipmentString = equipmentArray.getString(l); SportsEquipment equipment = equipmentSparseArray.get(getLastNumberOfJson(equipmentString)); equipmentSet.add(equipment); }*/ builder.activatedMuscles(muscleSet); // images List<File> imageList = new ArrayList<File>(); JSONArray imageArray = jsonExercise.getJSONArray("images"); for (int l = 0; l < imageArray.length(); l++) { String imageString = imageArray.getString(l); imageList.add(new File(imageString)); } builder.imagePath(imageList); mNewExerciseList.add(builder.build()); mNewExerciseBuilderList.add(builder); } }
From source file:com.epam.gepard.rest.jira.JiraSiteHandler.java
/** * Determine the date when a ticket status reached a specific status. * * @param tc is the caller tc//from ww w . j av a 2s . co m * @param ticket is the JIRA ticket id * @param statusName is the status we are looking for * @return with date string - from JIRA - when the expected status change has happened * @throws IOException in case of problem * @throws JSONException in case of problem */ public String getTicketStatusChangeDate(final GepardTestClass tc, final String ticket, final String statusName) throws IOException, JSONException { String newTicketInfo = ticket; String ticketHistory = getTicketHistory(tc, ticket); JSONObject obj = new JSONObject(ticketHistory); obj = obj.getJSONObject("changelog"); String startedDate = null; JSONArray arr = obj.getJSONArray("histories"); for (int l = 0; l < arr.length(); l++) { String changeDate = arr.getJSONObject(l).getString("created"); JSONArray changes = arr.getJSONObject(l).getJSONArray("items"); for (int m = 0; m < changes.length(); m++) { String change = changes.getString(m); // example: "\"toString\":\"In Progress\"" String statusChangeToName = "\"toString\":\"" + statusName + "\""; if (change.contains(STATUS_CHANGE_TEXT) && change.contains(statusChangeToName)) { if (startedDate == null) { startedDate = changeDate; tc.logComment( "Ticket: " + ticket + " was changed to \"" + statusName + "\" at " + changeDate); } } } } if (startedDate == null) { tc.logComment("Ticket: " + ticket + " change to \"" + statusName + "\" status cannot be identified."); } return startedDate; }
From source file:com.samsung.richnotification.RichNotification.java
/** * Executes the request and returns PluginResult. * * @param action//from w w w .j a v a 2 s .c o m * The action to execute. * @param data * JSONArray of arguments for the plugin. * @param callbackContext * The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. */ @Override public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException { if (Log.isLoggable(RICHNOTI, Log.DEBUG)) Log.d(TAG, "execute(): callbackID - " + callbackContext.getCallbackId()); mContext = this.cordova.getActivity(); // Do not allow apis if metadata is missing if (!pluginMetadata) { callbackContext.error("METADATA_MISSING"); Log.e(TAG, "Metadata is missing"); return false; } if (action.equals("isSupported")) { if (isRichNotificationSupported(callbackContext)) { callbackContext.success(); return true; } return false; } else if (action.equals("registerEventListeners")) { return registerRichNotificationEventListeners(callbackContext); } else if (action.equals("send")) { return sendRichNotification(data, callbackContext); } else if (action.equals("dismiss")) { String uuid = data.getString(0); // There will be just one array-element i.e. the UUID return dismissRichNotification(uuid, callbackContext); } else if (action.equals("isConnected")) { // initRichNotification will throw the DEVICE_NOT_CONNECTED error if (!initRichNotification(callbackContext)) { Log.e(TAG, "Initialization failed."); return false; } else { if (Log.isLoggable(RICHNOTI, Log.DEBUG)) Log.d(TAG, "Connected to gear"); callbackContext.success(); return true; } } return true; }
From source file:com.hichinaschool.flashcards.libanki.Sched.java
private List<Long> _fillDyn(JSONObject deck) { JSONArray terms; List<Long> ids;/*from www . ja va2 s . c om*/ try { terms = deck.getJSONArray("terms").getJSONArray(0); String search = terms.getString(0); int limit = terms.getInt(1); int order = terms.getInt(2); String orderlimit = _dynOrder(order, limit); search += " -is:suspended -is:buried -deck:filtered"; ids = mCol.findCards(search, orderlimit); if (ids.isEmpty()) { return ids; } // move the cards over _moveToDyn(deck.getLong("id"), ids); } catch (JSONException e) { throw new RuntimeException(e); } return ids; }
From source file:com.BreakingBytes.SifterReader.SifterReader.java
private String getFilterSlug() { String projDetailURL = new String(); int issuesPerPage = IssuesActivity.MAX_PER_PAGE; JSONArray status = new JSONArray(); JSONArray priority = new JSONArray(); int numStatuses; int numPriorities; boolean[] filterStatus; boolean[] filterPriority; try {/*from w w w.j a va 2s . c om*/ JSONObject filters = mSifterHelper.getFiltersFile(); if (filters.length() == 0) return new String(); issuesPerPage = filters.getInt(IssuesActivity.PER_PAGE); status = filters.getJSONArray(IssuesActivity.STATUS); priority = filters.getJSONArray(IssuesActivity.PRIORITY); numStatuses = status.length(); numPriorities = priority.length(); filterStatus = new boolean[numStatuses]; filterPriority = new boolean[numPriorities]; for (int i = 0; i < numStatuses; i++) filterStatus[i] = status.getBoolean(i); for (int i = 0; i < numPriorities; i++) filterPriority[i] = priority.getBoolean(i); } catch (Exception e) { e.printStackTrace(); mSifterHelper.onException(e.toString()); return new String(); } projDetailURL = "?" + IssuesActivity.PER_PAGE + "=" + issuesPerPage; projDetailURL += "&" + IssuesActivity.GOTO_PAGE + "=1"; JSONObject statuses = new JSONObject(); JSONObject priorities = new JSONObject(); JSONArray statusNames = new JSONArray(); JSONArray priorityNames = new JSONArray(); try { JSONObject sifterJSONObject = mSifterHelper.getSifterFilters(); statuses = sifterJSONObject.getJSONObject(IssuesActivity.STATUSES); priorities = sifterJSONObject.getJSONObject(IssuesActivity.PRIORITIES); statusNames = statuses.names(); priorityNames = priorities.names(); } catch (Exception e) { e.printStackTrace(); mSifterHelper.onException(e.toString()); return new String(); } try { String filterSlug = "&s="; for (int i = 0; i < numStatuses; i++) { if (filterStatus[i]) filterSlug += String.valueOf(statuses.getInt(statusNames.getString(i))) + "-"; } if (filterSlug.length() > 3) { filterSlug = filterSlug.substring(0, filterSlug.length() - 1); projDetailURL += filterSlug; } filterSlug = "&p="; for (int i = 0; i < numPriorities; i++) { if (filterPriority[i]) filterSlug += String.valueOf(priorities.getInt(priorityNames.getString(i))) + "-"; } if (filterSlug.length() > 3) { filterSlug = filterSlug.substring(0, filterSlug.length() - 1); projDetailURL += filterSlug; } } catch (JSONException e) { e.printStackTrace(); mSifterHelper.onException(e.toString()); return new String(); } return projDetailURL; }
From source file:com.jskaleel.xml.JSONObject.java
/** * Produce a JSONArray containing the values of the members of this * JSONObject.//from ww w.j a v a 2s . co m * * @param names * A JSONArray containing a list of key strings. This determines * the sequence of the values in the result. * @return A JSONArray of values. * @throws JSONException * If any of the values are non-finite numbers. */ public JSONArray toJSONArray(JSONArray names) throws JSONException { if (names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); for (int i = 0; i < names.length(); i += 1) { ja.put(this.opt(names.getString(i))); } return ja; }
From source file:org.forgerock.openam.mobile.example.authentication.activities.SettingsActivity.java
/** * when we get the list of cookies returned from the server *//*w ww. jav a2 s .com*/ private void cookieDomainSuccess(String domains) { final JSONObject json; final JSONArray domainArray; final List<String> options = new ArrayList<String>(); try { json = new JSONObject(domains); domainArray = json.getJSONArray("domains"); for (int i = 0; i < domainArray.length(); i++) { options.add(domainArray.getString(i)); } } catch (JSONException e) { Log.e(TAG, "Unable to objectify the returned JSON.", e); } final String[] optArray = options.toArray(new String[options.size()]); final EditText cookieDomainEdit = (EditText) findViewById(R.id.settings_cookie_domain_text); final AlertDialog.Builder builder = new AlertDialog.Builder(SettingsActivity.this); builder.setTitle("Select Domain"); builder.setItems(optArray, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); cookieDomainEdit.setText(optArray[which]); } }); builder.create().show(); }
From source file:com.connectsdk.cordova.DiscoveryManagerWrapper.java
public void configure(JSONObject config) throws JSONException { if (config.has("pairingLevel")) { String pairingLevel = config.getString("pairingLevel"); if ("off".equals(pairingLevel)) { discoveryManager.setPairingLevel(PairingLevel.OFF); } else if ("on".equals(pairingLevel)) { discoveryManager.setPairingLevel(PairingLevel.ON); }/*w ww . j a va 2 s . c o m*/ } if (config.has("capabilityFilters")) { JSONArray filters = config.getJSONArray("capabilityFilters"); ArrayList<CapabilityFilter> capabilityFilters = new ArrayList<CapabilityFilter>(); for (int i = 0; i < filters.length(); i++) { JSONArray filter = filters.getJSONArray(i); CapabilityFilter capabilityFilter = new CapabilityFilter(); for (int j = 0; j < filter.length(); j++) { capabilityFilter.addCapability(filter.getString(j)); } capabilityFilters.add(capabilityFilter); } discoveryManager.setCapabilityFilters(capabilityFilters); } }
From source file:org.cloudsky.cordovaPlugins.BarcodeminCDV.java
/** * Starts an intent to scan and decode a barcode. */// ww w . j a va 2s . c om public void scan(final JSONArray args) { final CordovaPlugin that = this; cordova.getThreadPool().execute(new Runnable() { public void run() { Intent intentScan = new Intent(SCAN_INTENT); intentScan.addCategory(Intent.CATEGORY_DEFAULT); // add config as intent extras if (args.length() > 0) { JSONObject obj; JSONArray names; String key; Object value; for (int i = 0; i < args.length(); i++) { try { obj = args.getJSONObject(i); } catch (JSONException e) { Log.i("CordovaLog", e.getLocalizedMessage()); continue; } names = obj.names(); for (int j = 0; j < names.length(); j++) { try { key = names.getString(j); value = obj.get(key); if (value instanceof Integer) { intentScan.putExtra(key, (Integer) value); } else if (value instanceof String) { intentScan.putExtra(key, (String) value); } } catch (JSONException e) { Log.i("CordovaLog", e.getLocalizedMessage()); } } intentScan.putExtra(Intents.Scan.CAMERA_ID, obj.optBoolean(PREFER_FRONTCAMERA, false) ? 1 : 0); intentScan.putExtra(Intents.Scan.SHOW_FLIP_CAMERA_BUTTON, obj.optBoolean(SHOW_FLIP_CAMERA_BUTTON, false)); if (obj.has(FORMATS)) { intentScan.putExtra(Intents.Scan.FORMATS, obj.optString(FORMATS)); } if (obj.has(PROMPT)) { intentScan.putExtra(Intents.Scan.PROMPT_MESSAGE, obj.optString(PROMPT)); } //if (obj.has(ORIENTATION)) { //intentScan.putExtra(Intents.Scan.ORIENTATION_LOCK, obj.optString(ORIENTATION)); intentScan.putExtra(Intents.Scan.ORIENTATION_LOCK, "false"); //} } } // avoid calling other phonegap apps intentScan.setPackage(that.cordova.getActivity().getApplicationContext().getPackageName()); that.cordova.startActivityForResult(that, intentScan, REQUEST_CODE); } }); }