List of usage examples for org.json JSONObject getInt
public int getInt(String key) throws JSONException
From source file:org.b3log.solo.processor.util.Filler.java
/** * Fills header.ftl./*from w w w. j ava2 s.com*/ * * @param request the specified HTTP servlet request * @param dataModel data model * @param preference the specified preference * @throws ServiceException service exception */ public void fillBlogHeader(final HttpServletRequest request, final Map<String, Object> dataModel, final JSONObject preference) throws ServiceException { Stopwatchs.start("Fill Header"); try { LOGGER.fine("Filling header...."); dataModel.put(Preference.ARTICLE_LIST_DISPLAY_COUNT, preference.getInt(Preference.ARTICLE_LIST_DISPLAY_COUNT)); dataModel.put(Preference.ARTICLE_LIST_PAGINATION_WINDOW_SIZE, preference.getInt(Preference.ARTICLE_LIST_PAGINATION_WINDOW_SIZE)); dataModel.put(Preference.LOCALE_STRING, preference.getString(Preference.LOCALE_STRING)); dataModel.put(Preference.BLOG_TITLE, preference.getString(Preference.BLOG_TITLE)); dataModel.put(Preference.BLOG_SUBTITLE, preference.getString(Preference.BLOG_SUBTITLE)); dataModel.put(Preference.HTML_HEAD, preference.getString(Preference.HTML_HEAD)); dataModel.put(Preference.META_KEYWORDS, preference.getString(Preference.META_KEYWORDS)); dataModel.put(Preference.META_DESCRIPTION, preference.getString(Preference.META_DESCRIPTION)); dataModel.put(Common.YEAR, String.valueOf(Calendar.getInstance().get(Calendar.YEAR))); final String noticeBoard = preference.getString(Preference.NOTICE_BOARD); dataModel.put(Preference.NOTICE_BOARD, noticeBoard); final Query query = new Query().setPageCount(1); final JSONObject result = userRepository.get(query); final JSONArray users = result.getJSONArray(Keys.RESULTS); final List<JSONObject> userList = CollectionUtils.jsonArrayToList(users); dataModel.put(User.USERS, userList); for (final JSONObject user : userList) { user.remove(User.USER_EMAIL); } final String skinDirName = (String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME); dataModel.put(Skin.SKIN_DIR_NAME, skinDirName); Keys.fillServer(dataModel); Keys.fillRuntime(dataModel); fillMinified(dataModel); fillPageNavigations(dataModel); fillStatistic(dataModel); } catch (final JSONException e) { LOGGER.log(Level.SEVERE, "Fills blog header failed", e); throw new ServiceException(e); } catch (final RepositoryException e) { LOGGER.log(Level.SEVERE, "Fills blog header failed", e); throw new ServiceException(e); } finally { Stopwatchs.end(); } }
From source file:org.softcatala.corrector.LanguageToolParsing.java
public Suggestion[] GetSuggestions(String jsonText) { ArrayList<Suggestion> suggestions = new ArrayList<Suggestion>(); try {/*from www .java 2s. c o m*/ JSONObject json = new JSONObject(jsonText); JSONArray matches = json.getJSONArray("matches"); for (int i = 0; i < matches.length(); i++) { JSONObject match = matches.getJSONObject(i); JSONArray replacements = match.getJSONArray("replacements"); JSONObject rule = match.getJSONObject("rule"); String ruleId = rule.getString("id"); // Since we process fragments we need to skip the upper case // suggestion if (ruleId.equals("UPPERCASE_SENTENCE_START") == true) continue; Suggestion suggestion = new Suggestion(); if (replacements.length() == 0) { String message = match.getString("message"); String msgText = String.format("(%s)", message); suggestion.Text = new String[] { msgText }; } else { ArrayList<String> list = new ArrayList<String>(); for (int r = 0; r < replacements.length(); r++) { JSONObject replacement = replacements.getJSONObject(r); String value = replacement.getString("value"); list.add(value); } suggestion.Text = list.toArray(new String[list.size()]); } suggestion.Position = match.getInt("offset"); suggestion.Length = match.getInt("length"); suggestions.add(suggestion); Log.d(TAG, "Request result: " + suggestion.Position + " Len:" + suggestion.Length); } } catch (Exception e) { Log.e(TAG, "GetSuggestions", e); } return suggestions.toArray(new Suggestion[0]); }
From source file:com.sdspikes.fireworks.FireworksTurn.java
static public FireworksTurn unpersist(JSONObject obj) { FireworksTurn retVal = new FireworksTurn(); try {// www. j av a 2 s.co m if (!obj.has("state")) { return null; } else { retVal.state = new GameState(obj.getJSONObject("state")); } if (obj.has("turn")) { retVal.turnCounter = obj.getInt("turn"); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return retVal; }
From source file:com.ecml.MidiOptions.java
/** Initialize the options from a json string * /*from w w w . j a v a 2 s.c o m*/ * @param jsonString */ public static MidiOptions fromJson(String jsonString) { if (jsonString == null) { return null; } MidiOptions options = new MidiOptions(); try { JSONObject json = new JSONObject(jsonString); JSONArray jsonTracks = json.getJSONArray("tracks"); options.tracks = new boolean[jsonTracks.length()]; for (int i = 0; i < options.tracks.length; i++) { options.tracks[i] = jsonTracks.getBoolean(i); } JSONArray jsonMute = json.getJSONArray("mute"); options.mute = new boolean[jsonMute.length()]; for (int i = 0; i < options.mute.length; i++) { options.mute[i] = jsonMute.getBoolean(i); } JSONArray jsonInstruments = json.getJSONArray("instruments"); options.instruments = new int[jsonInstruments.length()]; for (int i = 0; i < options.instruments.length; i++) { options.instruments[i] = jsonInstruments.getInt(i); } if (json.has("time")) { JSONObject jsonTime = json.getJSONObject("time"); int numer = jsonTime.getInt("numerator"); int denom = jsonTime.getInt("denominator"); int quarter = jsonTime.getInt("quarter"); int tempo = jsonTime.getInt("tempo"); options.time = new TimeSignature(numer, denom, quarter, tempo); } options.useDefaultInstruments = json.getBoolean("useDefaultInstruments"); options.scrollVert = json.getBoolean("scrollVert"); options.showPiano = json.getBoolean("showPiano"); options.showNoteColors = json.getBoolean("showNoteColors"); options.showLyrics = json.getBoolean("showLyrics"); options.delay = json.getInt("delay"); options.twoStaffs = json.getBoolean("twoStaffs"); options.showNoteLetters = json.getInt("showNoteLetters"); options.transpose = json.getInt("transpose"); options.key = json.getInt("key"); options.combineInterval = json.getInt("combineInterval"); options.shade1Color = json.getInt("shade1Color"); options.shade2Color = json.getInt("shade2Color"); options.showMeasures = json.getBoolean("showMeasures"); options.playMeasuresInLoop = json.getBoolean("playMeasuresInLoop"); options.playMeasuresInLoopStart = json.getInt("playMeasuresInLoopStart"); options.playMeasuresInLoopEnd = json.getInt("playMeasuresInLoopEnd"); } catch (Exception e) { return null; } return options; }
From source file:org.prx.prp.utility.ParsedJSONObject.java
private void storeId(JSONObject object) { try {//from w w w .j av a2s . co m this.id = object.getInt("id"); } catch (JSONException e) { e.printStackTrace(); } }
From source file:org.rapidandroid.activity.FormCreator.java
private void restoreFieldFromState(JSONObject fieldjson) { if (mCurrentFields == null) { mCurrentFields = new ArrayList<Field>(); }/* w w w . jav a 2 s.co m*/ try { Field newField = new Field(); newField.setFieldId(-1); newField.setName(fieldjson.getString(ResultConstants.RESULT_KEY_FIELDNAME)); newField.setDescription(fieldjson.getString(ResultConstants.RESULT_KEY_DESCRIPTION)); int fieldTypeID = fieldjson.getInt(ResultConstants.RESULT_KEY_FIELDTYPE_ID); ITokenParser fieldtype = ModelTranslator.getFieldType(fieldTypeID); newField.setFieldType(fieldtype); int listSize = mCurrentFields.size(); for (int i = 0; i < listSize; i++) { Field existingField = mCurrentFields.get(i); if (existingField.getName().equals(newField.getName())) { return; } } if (listSize > 0) { listSize = listSize - 1; } newField.setSequenceId(listSize); mCurrentFields.add(newField); fieldViewAdapter.notifyDataSetChanged(); // updateFieldList(); } catch (Exception ex) { Log.d("FormCreator", ex.getMessage()); } }
From source file:com.esri.cordova.geolocation.AdvancedGeolocation.java
private void parseArgs(JSONArray args) { Log.d(TAG, "Execute args: " + args.toString()); if (args.length() > 0) { try {/*from ww w. j a va2 s .c o m*/ final JSONObject obj = args.getJSONObject(0); _minTime = obj.getLong("minTime"); _minDistance = obj.getLong("minDistance"); _noWarn = obj.getBoolean("noWarn"); _providers = obj.getString("providers"); _useCache = obj.getBoolean("useCache"); _returnSatelliteData = obj.getBoolean("satelliteData"); _buffer = obj.getBoolean("buffer"); _signalStrength = obj.getBoolean("signalStrength"); _bufferSize = obj.getInt("bufferSize"); } catch (Exception exc) { Log.d(TAG, ErrorMessages.INCORRECT_CONFIG_ARGS + ", " + exc.getMessage()); sendCallback(PluginResult.Status.ERROR, ErrorMessages.INCORRECT_CONFIG_ARGS + ", " + exc.getMessage()); } } }
From source file:com.wglxy.example.dashL.SearchActivity.java
ArrayList<User> parseJSON(String results) throws JSONException, NullPointerException { ArrayList<User> list = new ArrayList<User>(); JSONObject jsonResult = new JSONObject(results); int status = jsonResult.getInt("status"); int numResults = jsonResult.getInt("numResults"); if (status != 200 && numResults <= 0) return list; else {/* ww w . j a va2 s.c o m*/ JSONArray arr = jsonResult.getJSONArray("results"); Log.e(LOG_TAG, "results: " + arr.length()); for (int i = 0; i < arr.length(); i++) { JSONObject jsonObject = arr.getJSONObject(i); User user = new User(); int id = jsonObject.getInt("id"); String email = jsonObject.getString("email"); String first_name = jsonObject.getString("first_name"); String last_name = jsonObject.getString("last_name"); String business_name = jsonObject.getString("business_name"); String services = jsonObject.getString("services"); String address = jsonObject.getString("address"); int stars = jsonObject.getInt("stars"); String image = Constants.API_BASE_IMAGE_URL + jsonObject.getString("image"); Log.e(LOG_TAG, "image: " + image); user.setId(id); user.setEmail(email); user.setFirst_name(first_name); user.setLast_name(last_name); user.setBusiness_name(business_name); user.setAddress(address); user.setServices(services); user.setStars(stars); user.setImage(image); list.add(user); } return list; } }
From source file:org.hydracache.client.partition.PartitionAwareClient.java
@Override public synchronized List<Identity> listNodes() throws Exception { log.info("Retrieving list of nodes."); RequestMessage requestMessage = new RequestMessage(); requestMessage.setMethod(GET);/*from w w w . j av a 2 s. co m*/ requestMessage.setPath("registry"); // Pick a random node to connect to Random rnd = new Random(); int nextInt = rnd.nextInt(seedServerIds.size()); Identity identity = seedServerIds.get(nextInt); ResponseMessage responseMessage = messager.sendMessage(identity, nodePartition, requestMessage); if (responseMessage == null) throw new ClientException("Failed to retrieve node registry."); List<Identity> identities = new LinkedList<Identity>(); String registry = new String(responseMessage.getResponseBody()); log.debug("Received registry: " + registry); JSONArray seedServerArray = new JSONArray(registry); for (int i = 0; i < seedServerArray.length(); i++) { JSONObject seedServer = seedServerArray.getJSONObject(i); identities.add(new Identity(InetAddress.getByName(seedServer.getString(IP)), seedServer.getInt(PORT))); } return identities; }
From source file:org.loklak.server.Authorization.java
public int getRequestFrequency(String path) { if (!this.json.has("frequency")) return -1; JSONObject paths = this.json.getJSONObject("frequency"); if (!paths.has(path)) return -1; return paths.getInt(path); }