List of usage examples for org.json JSONObject getInt
public int getInt(String key) throws JSONException
From source file:com.soomla.store.domain.data.BalanceDrivenPriceModel.java
/** * Creates a {@link BalanceDrivenPriceModel} with the given JSONObject. * @param jsonObject is a JSONObject representation of the required {@link BalanceDrivenPriceModel}. * @return an instance of {@link BalanceDrivenPriceModel}. * @throws JSONException//ww w . ja v a2 s .co m */ public static BalanceDrivenPriceModel fromJSONObject(JSONObject jsonObject) throws JSONException { JSONArray valuesPerBalanceJSON = jsonObject.getJSONArray(JSONConsts.GOOD_PRICE_MODEL_VALUES); ArrayList<HashMap<String, Integer>> valuesPerBalance = new ArrayList<HashMap<String, Integer>>( valuesPerBalanceJSON.length()); for (int i = 0; i < valuesPerBalanceJSON.length(); i++) { JSONObject valuesJSON = valuesPerBalanceJSON.getJSONObject(i); Iterator<?> valuesKeys = valuesJSON.keys(); HashMap<String, Integer> values = new HashMap<String, Integer>(); while (valuesKeys.hasNext()) { String key = (String) valuesKeys.next(); values.put(key, valuesJSON.getInt(key)); } valuesPerBalance.add(i, values); } return new BalanceDrivenPriceModel(valuesPerBalance); }
From source file:com.dedipower.portal.android.ColoLanding.java
public void onCreate(Bundle savedInstanceState) { API.SessionID = getIntent().getStringExtra("sessionid"); super.onCreate(savedInstanceState); setContentView(R.layout.cololanding_iclone); //Temp/*from w w w. ja va 2s .c o m*/ list = (ListView) findViewById(R.id.ColoCabList); final ProgressDialog dialog = ProgressDialog.show(this, "DediPortal", "Please wait: loading data....", true); final Handler handler = new Handler() { public void handleMessage(Message msg) { dialog.dismiss(); if (Success.equals("true")) { UpdateErrorMessage(ErrorMessage); ColoRacksAdaptor adapter = new ColoRacksAdaptor(ColoLanding.this, listOfColoRacks); list.setAdapter(adapter); } else { UpdateErrorMessage(ErrorMessage); } } }; Thread dataPreload = new Thread() { public void run() { try { Colo = API.PortalQuery("colocation", "none"); Success = Colo.getString("success"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occurred."; //UpdateErrorMessage("An unrecoverable JSON Exception occurred."); } if (Success.equals("false")) { try { //UpdateErrorMessage(Colo.getString("msg")); ErrorMessage = Colo.getString("msg"); } catch (JSONException e) { ErrorMessage = "An unrecoverable JSON Exception occured."; //UpdateErrorMessage("An unrecoverable JSON Exception occured."); } } else { Log.i("APIFuncs", Colo.toString()); try { ColoCabs = Colo.getJSONArray("colocation"); ErrorMessage = ""; //UpdateErrorMessage(""); } catch (JSONException e) { ErrorMessage = "There are no Co-Location Cabinets in your account."; //UpdateErrorMessage("There are no Co-Location Cabinets in your account."); } int ColoCount = ColoCabs.length(); if (ColoCount == 0) { //UpdateErrorMessage("There are no colocation cabinets for your account."); ErrorMessage = "There are no colocation cabinets for your account."; handler.sendEmptyMessage(0); return; } for (int i = 0; i < ColoCount; i++) { JSONObject CurrentColo = null; try { CurrentColo = ColoCabs.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs", e1.getMessage()); } try { listOfColoRacks.add(new ColoRacks(CurrentColo.getString("ip"), CurrentColo.getString("servercode"), CurrentColo.getString("facility"), CurrentColo.getInt("bandwidth"), CurrentColo.getString("bandwidthTotal"), CurrentColo.getInt("transferlimit"), CurrentColo.getString("state"))); } catch (JSONException e) { Log.e("APIFuncs", e.getMessage()); } } } handler.sendEmptyMessage(0); } }; dataPreload.start(); //temp /*try { Colo = API.PortalQuery("colocation", "none"); Success = Colo.getString("success"); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); //Toast.makeText(ColoLanding.this, "An unrecoverable JSON Exception occured.", Toast.LENGTH_LONG).show(); } if(Success == "false") { try { UpdateErrorMessage(Colo.getString("msg")); } catch (JSONException e) { UpdateErrorMessage("An unrecoverable JSON Exception occured."); } } else { Log.i("APIFuncs",Colo.toString()); try { ColoCabs = Colo.getJSONArray("colocation"); UpdateErrorMessage(""); } catch (JSONException e) { UpdateErrorMessage("There are no Co-Location Cabinets in your account."); } //OK lets actually do something useful ListView list = (ListView)findViewById(R.id.ColoCabList); List<ColoRacks> listOfColoRacks = new ArrayList<ColoRacks>(); int ColoCount = ColoCabs.length(); if(ColoCount == 0) { UpdateErrorMessage("There are no colocation cabinets for your account."); return; } for(int i = 0; i < ColoCount; i++) { JSONObject CurrentColo = null; try { CurrentColo = ColoCabs.getJSONObject(i); } catch (JSONException e1) { Log.e("APIFuncs",e1.getMessage()); } try { listOfColoRacks.add(new ColoRacks(CurrentColo.getString("ip"), CurrentColo.getString("servercode"), CurrentColo.getString("facility"), CurrentColo.getInt("bandwidth"), CurrentColo.getString("bandwidthTotal"), CurrentColo.getInt("transferlimit"), CurrentColo.getString("state"))); } catch (JSONException e) { Log.e("APIFuncs",e.getMessage()); } } ColoRacksAdaptor adapter = new ColoRacksAdaptor(this, listOfColoRacks); list.setAdapter(adapter); }*/ }
From source file:bpv.neurosky.connector.ThinkGearSocket.java
private void parsePacket(JSONObject data) { Iterator<?> itr = data.keys(); while (itr.hasNext()) { Object e = itr.next();//from w w w . jav a 2 s. c o m String key = e.toString(); try { if (key.matches("poorSignalLevel")) { triggerPoorSignalEvent(data.getInt(e.toString())); } if (key.matches("rawEeg")) { int rawValue = (Integer) data.get("rawEeg"); raw[index] = rawValue; index++; if (index == 512) { index = 0; int rawCopy[] = new int[512]; //TODO: Ajusta para funcionar na implementao atual rawCopy = Arrays.copyOf(raw, raw.length); triggerRawEvent(rawCopy); } } if (key.matches("blinkStrength")) { triggerBlinkEvent(data.getInt(e.toString())); } if (key.matches("eSense")) { JSONObject esense = data.getJSONObject("eSense"); triggerAttentionEvent(esense.getInt("attention")); triggerMeditationEvent(esense.getInt("meditation")); } if (key.matches("eegPower")) { JSONObject eegPower = data.getJSONObject("eegPower"); triggerEEGEvent(eegPower.getInt("delta"), eegPower.getInt("theta"), eegPower.getInt("lowAlpha"), eegPower.getInt("highAlpha"), eegPower.getInt("lowBeta"), eegPower.getInt("highBeta"), eegPower.getInt("lowGamma"), eegPower.getInt("highGamma")); //System.out.println(key); } } catch (Exception ex) { ex.printStackTrace(); } } // }
From source file:com.hichinaschool.flashcards.anki.Preferences.java
@Override protected void onCreate(Bundle savedInstanceState) { // Workaround for bug 4611: http://code.google.com/p/android/issues/detail?id=4611 if (AnkiDroidApp.SDK_VERSION >= 7 && AnkiDroidApp.SDK_VERSION <= 10) { Themes.applyTheme(this, Themes.THEME_ANDROID_DARK); }// w w w .j ava 2s.c o m super.onCreate(savedInstanceState); mCol = AnkiDroidApp.getCol(); mPrefMan = getPreferenceManager(); mPrefMan.setSharedPreferencesName(AnkiDroidApp.SHARED_PREFS_NAME); addPreferencesFromResource(R.xml.preferences); swipeCheckboxPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("swipe"); zoomCheckboxPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("zoom"); keepScreenOnCheckBoxPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("keepScreenOn"); showAnswerCheckBoxPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("timeoutAnswer"); animationsCheckboxPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("themeAnimations"); useBackupPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("useBackup"); asyncModePreference = (CheckBoxPreference) getPreferenceScreen().findPreference("asyncMode"); eInkDisplayPreference = (CheckBoxPreference) getPreferenceScreen().findPreference("eInkDisplay"); fadeScrollbars = (CheckBoxPreference) getPreferenceScreen().findPreference("fadeScrollbars"); // ListPreference listpref = (ListPreference) getPreferenceScreen().findPreference("theme"); convertFenText = (CheckBoxPreference) getPreferenceScreen().findPreference("convertFenText"); fixHebrewText = (CheckBoxPreference) getPreferenceScreen().findPreference("fixHebrewText"); syncAccount = (Preference) getPreferenceScreen().findPreference("syncAccount"); showEstimates = (CheckBoxPreference) getPreferenceScreen().findPreference("showEstimates"); showProgress = (CheckBoxPreference) getPreferenceScreen().findPreference("showProgress"); learnCutoff = (NumberRangePreference) getPreferenceScreen().findPreference("learnCutoff"); timeLimit = (NumberRangePreference) getPreferenceScreen().findPreference("timeLimit"); useCurrent = (ListPreference) getPreferenceScreen().findPreference("useCurrent"); newSpread = (ListPreference) getPreferenceScreen().findPreference("newSpread"); dayOffset = (SeekBarPreference) getPreferenceScreen().findPreference("dayOffset"); // String theme = listpref.getValue(); // animationsCheckboxPreference.setEnabled(theme.equals("2") || theme.equals("3")); zoomCheckboxPreference.setEnabled(!swipeCheckboxPreference.isChecked()); initializeLanguageDialog(); initializeCustomFontsDialog(); if (mCol != null) { // For collection preferences, we need to fetch the correct values from the collection mStartDate = GregorianCalendar.getInstance(); Timestamp timestamp = new Timestamp(mCol.getCrt() * 1000); mStartDate.setTimeInMillis(timestamp.getTime()); dayOffset.setValue(mStartDate.get(Calendar.HOUR_OF_DAY)); try { JSONObject conf = mCol.getConf(); learnCutoff.setValue(conf.getInt("collapseTime") / 60); timeLimit.setValue(conf.getInt("timeLim") / 60); showEstimates.setChecked(conf.getBoolean("estTimes")); showProgress.setChecked(conf.getBoolean("dueCounts")); newSpread.setValueIndex(conf.getInt("newSpread")); useCurrent.setValueIndex(conf.getBoolean("addToCur") ? 0 : 1); } catch (JSONException e) { throw new RuntimeException(); } catch (NumberFormatException e) { throw new RuntimeException(); } } else { // It's possible to open the preferences from the loading screen if no SD card is found. // In that case, there will be no collection loaded, so we need to disable the settings // that read from and write to the collection. dayOffset.setEnabled(false); learnCutoff.setEnabled(false); timeLimit.setEnabled(false); showEstimates.setEnabled(false); showProgress.setEnabled(false); newSpread.setEnabled(false); useCurrent.setEnabled(false); } for (String key : mShowValueInSummList) { updateListPreference(key); } for (String key : mShowValueInSummSeek) { updateSeekBarPreference(key); } for (String key : mShowValueInSummEditText) { updateEditTextPreference(key); } for (String key : mShowValueInSummNumRange) { updateNumberRangePreference(key); } if (AnkiDroidApp.SDK_VERSION <= 4) { fadeScrollbars.setChecked(false); fadeScrollbars.setEnabled(false); } }
From source file:net.dahanne.gallery3.client.utils.ItemUtils.java
private static Entity parseJSONToEntity(JSONObject jsonResult) throws JSONException { Entity entity = new Entity(); JSONObject entityJSON = jsonResult.getJSONObject("entity"); entity.setId(entityJSON.getInt("id")); entity.setCaptured(entityJSON.getString("captured").equals("null") ? 0L : Integer.parseInt(entityJSON.getString("captured"))); entity.setCreated(entityJSON.getString("created").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("created"))); entity.setDescription(entityJSON.getString("description")); entity.setHeight(entityJSON.getString("height").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("height"))); entity.setLevel(entityJSON.getInt("level")); entity.setMimeType(/*from w w w. ja v a 2 s. c o m*/ entityJSON.getString("mime_type").equals("null") ? null : entityJSON.getString("mime_type")); entity.setName(entityJSON.getString("name").equals("null") ? null : entityJSON.getString("name")); entity.setOwnerId(entityJSON.getString("owner_id").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("owner_id"))); entity.setRandKey(entityJSON.getString("rand_key").equals("null") ? 0f : Float.parseFloat(entityJSON.getString("rand_key"))); entity.setResizeHeight(entityJSON.getString("resize_height").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("resize_height"))); entity.setResizeWidth(entityJSON.getString("resize_width").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("resize_width"))); entity.setSlug(entityJSON.getString("slug").equals("null") ? null : entityJSON.getString("slug")); entity.setSortColumn(entityJSON.getString("sort_column")); entity.setSortOrder(entityJSON.getString("sort_order")); entity.setThumbHeight(entityJSON.getString("thumb_height").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("thumb_height"))); entity.setThumbWidth(entityJSON.getString("thumb_width").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("thumb_width"))); entity.setTitle(entityJSON.getString("title")); entity.setType(entityJSON.getString("type")); entity.setUpdated(entityJSON.getString("updated").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("updated"))); entity.setViewCount(entityJSON.getInt("view_count")); entity.setWidth( entityJSON.getString("width").equals("null") ? 0 : Integer.parseInt(entityJSON.getString("width"))); entity.setView1(entityJSON.getInt("view_1")); entity.setView2(entityJSON.getInt("view_2")); entity.setWebUrl(entityJSON.getString("web_url")); try { entity.setThumbUrl( entityJSON.getString("thumb_url").equals("null") ? null : entityJSON.getString("thumb_url")); } catch (JSONException e) { // nothing to do, it's just that there is no thumb url } try { entity.setThumbSize(entityJSON.getInt("thumb_size")); } catch (JSONException e) { // nothing to do, it's just that there is no thumb size } try { entity.setThumbUrlPublic(entityJSON.getString("thumb_url_public")); } catch (JSONException e) { // nothing to do, it's just that there is no thumb url public } try { entity.setParent(ItemUtils.getItemIdFromUrl(entityJSON.getString("parent"))); } catch (JSONException e) { // nothing to do, it's just that there is no parent } entity.setCanEdit(entityJSON.getBoolean("can_edit")); if (entity.getType().equals("album")) { try { entity.setAlbumCover(entityJSON.getString("album_cover")); } catch (JSONException e) { // nothing to do, it's just that there is no album_cover } } if (entity.getType().equals("photo")) { entity.setFileUrl(entityJSON.getString("file_url")); entity.setFileSize(entityJSON.getInt("file_size")); try { entity.setFileUrlPublic(entityJSON.getString("file_url_public")); } catch (JSONException e) { // nothing to do, it's just that there is no album_cover } entity.setResizeUrl(entityJSON.getString("resize_url")); try { entity.setResizeSize(entityJSON.getInt("resize_size")); } catch (JSONException e) { // nothing to do, it's just that there is no album_cover } try { entity.setResizeUrlPublic(entityJSON.getString("resize_url_public")); } catch (JSONException e) { // nothing to do, it's just that there is no album_cover } } return entity; }
From source file:com.iStudy.Study.Renren.Util.java
/** * ?JSON?RenrenError.//from w ww.ja va 2 s. c o m * * @param JSON * @return */ private static RenrenError parseJson(String jsonResponse) { try { JSONObject json = new JSONObject(jsonResponse); int errorCode = json.getInt("error_code"); String errorMessage = json.getString("error_msg"); errorMessage = RenrenError.interpretErrorMessage(errorCode, errorMessage); return new RenrenError(errorCode, errorMessage, jsonResponse); } catch (JSONException e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:com.aokyu.dev.pocket.RetrieveResponse.java
public boolean isFavorited(String uid) throws JSONException { JSONObject obj = (JSONObject) get(uid); int state = -1; try {//from w w w . j a v a 2 s . com state = obj.getInt(Parameter.FAVORITE); return (state == 1); } catch (NumberFormatException e) { return false; } }
From source file:com.aokyu.dev.pocket.RetrieveResponse.java
public boolean isArticle(String uid) throws JSONException { JSONObject obj = (JSONObject) get(uid); int state = -1; try {/*from w ww .jav a2 s . c o m*/ state = obj.getInt(Parameter.IS_ARTICLE); return (state == 1); } catch (NumberFormatException e) { return false; } }
From source file:com.aokyu.dev.pocket.RetrieveResponse.java
public ImageState getImageState(String uid) throws JSONException { JSONObject obj = (JSONObject) get(uid); int state = -1; try {/*from ww w .j av a2 s.c o m*/ state = obj.getInt(Parameter.HAS_IMAGE); return ImageState.valueOf(state); } catch (NumberFormatException e) { return null; } }
From source file:com.aokyu.dev.pocket.RetrieveResponse.java
public VideoState getVideoState(String uid) throws JSONException { JSONObject obj = (JSONObject) get(uid); int state = -1; try {//from ww w.j a va2s. c om state = obj.getInt(Parameter.HAS_VIDEO); return VideoState.valueOf(state); } catch (NumberFormatException e) { return null; } }