List of usage examples for org.json JSONObject optString
public String optString(String key)
From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java
private void inflateInterestCalculationPeriodSpinner(ResponseBody result) { final List<InterestCalculationPeriodType> interestCalculationPeriodType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> interestCalculationPeriodTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try {//from w w w . j a v a2 s .c o m reader = new BufferedReader(new InputStreamReader(result.byteStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("interestCalculationPeriodTypeOptions")) { JSONArray interestCalculationPeriodTypes = obj.getJSONArray("interestCalculationPeriodTypeOptions"); for (int i = 0; i < interestCalculationPeriodTypes.length(); i++) { JSONObject interestCalculationPeriodTypeObject = interestCalculationPeriodTypes .getJSONObject(i); InterestCalculationPeriodType interestCalculationPeriod = new InterestCalculationPeriodType(); interestCalculationPeriod.setId(interestCalculationPeriodTypeObject.optInt("id")); interestCalculationPeriod.setValue(interestCalculationPeriodTypeObject.optString("value")); interestCalculationPeriodType.add(interestCalculationPeriod); interestCalculationPeriodTypeNames.add(interestCalculationPeriodTypeObject.optString("value")); interestCalculationPeriodTypeIdHashMap.put(interestCalculationPeriod.getValue(), interestCalculationPeriod.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> interestCalculationPeriodTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, interestCalculationPeriodTypeNames); interestCalculationPeriodTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_interestcalculationperiod.setAdapter(interestCalculationPeriodTypeAdapter); sp_interestcalculationperiod.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { interestCalculationPeriodTypeId = interestCalculationPeriodTypeIdHashMap .get(interestCalculationPeriodTypeNames.get(i)); Log.d("interestCalculation " + interestCalculationPeriodTypeNames.get(i), String.valueOf(interestCalculationPeriodTypeId)); if (interestCalculationPeriodTypeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_interestCalculationPeriod), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java
private void inflatetransactionProcessingStrategySpinner(ResponseBody result) { final List<TransactionProcessingStrategy> transactionProcessingStrategyType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> transactionProcessingStrategyTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try {//from w w w .ja v a 2 s . c om reader = new BufferedReader(new InputStreamReader(result.byteStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("transactionProcessingStrategyOptions")) { JSONArray transactionProcessingStrategyTypes = obj .getJSONArray("transactionProcessingStrategyOptions"); for (int i = 0; i < transactionProcessingStrategyTypes.length(); i++) { JSONObject transactionProcessingStrategyTypeObject = transactionProcessingStrategyTypes .getJSONObject(i); TransactionProcessingStrategy transactionProcessingStrategy = new TransactionProcessingStrategy(); transactionProcessingStrategy.setId(transactionProcessingStrategyTypeObject.optInt("id")); transactionProcessingStrategy .setName(transactionProcessingStrategyTypeObject.optString("name")); transactionProcessingStrategyType.add(transactionProcessingStrategy); transactionProcessingStrategyTypeNames .add(transactionProcessingStrategyTypeObject.optString("name")); transactionProcessingStrategyTypeIdHashMap.put(transactionProcessingStrategy.getName(), transactionProcessingStrategy.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> transactionProcessingStrategyAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, transactionProcessingStrategyTypeNames); transactionProcessingStrategyAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_repaymentstrategy.setAdapter(transactionProcessingStrategyAdapter); sp_repaymentstrategy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { transactionProcessingStrategyId = transactionProcessingStrategyTypeIdHashMap .get(transactionProcessingStrategyTypeNames.get(i)); Log.d("transactionProcessing " + transactionProcessingStrategyTypeNames.get(i), String.valueOf(transactionProcessingStrategyId)); if (transactionProcessingStrategyId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_transactionProcessingStrategy), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java
private void inflateFrequencyPeriodSpinner(ResponseBody result) { final List<TermFrequencyTypeOptions> termFrequencyType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> termFrequencyTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try {/*from w ww .j av a2 s . c o m*/ reader = new BufferedReader(new InputStreamReader(result.byteStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("termFrequencyTypeOptions")) { JSONArray termFrequencyTypes = obj.getJSONArray("termFrequencyTypeOptions"); for (int i = 0; i < termFrequencyTypes.length(); i++) { JSONObject termFrequencyTypeObject = termFrequencyTypes.getJSONObject(i); TermFrequencyTypeOptions termFrequency = new TermFrequencyTypeOptions(); termFrequency.setId(termFrequencyTypeObject.optInt("id")); termFrequency.setValue(termFrequencyTypeObject.optString("value")); termFrequencyType.add(termFrequency); termFrequencyTypeNames.add(termFrequencyTypeObject.optString("value")); termFrequencyTypeIdHashMap.put(termFrequency.getValue(), termFrequency.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> termFrequencyTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, termFrequencyTypeNames); termFrequencyTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_payment_periods.setAdapter(termFrequencyTypeAdapter); sp_payment_periods.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { loanTermFrequency = termFrequencyTypeIdHashMap.get(termFrequencyTypeNames.get(i)); Log.d("termFrequencyTypeId" + termFrequencyTypeNames.get(i), String.valueOf(loanTermFrequency)); if (loanTermFrequency != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.mifos.mifosxdroid.online.grouploanaccount.GroupLoanAccountFragment.java
@Override public void showLoanPurposeSpinner(ResponseBody result) { mResponse = result;/* ww w. jav a 2 s . c o m*/ inflateFrequencyPeriodSpinner(mResponse); inflateAmortizationSpinner(mResponse); inflateInterestCalculationPeriodSpinner(mResponse); //inflaterepaymentFrequencyTypeOptionsSpinner(); inflatetransactionProcessingStrategySpinner(mResponse); final List<LoanPurposeOptions> loanPurposeOptionsType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> loanPurposeOptionsTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try { reader = new BufferedReader(new InputStreamReader(result.byteStream())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("loanPurposeOptions")) { JSONArray loanPurposeOptionsTypes = obj.getJSONArray("loanPurposeOptions"); for (int i = 0; i < loanPurposeOptionsTypes.length(); i++) { JSONObject loanPurposeOptionsTypesObject = loanPurposeOptionsTypes.getJSONObject(i); LoanPurposeOptions loanpurpose = new LoanPurposeOptions(); loanpurpose.setId(loanPurposeOptionsTypesObject.optInt("id")); loanpurpose.setName(loanPurposeOptionsTypesObject.optString("name")); loanPurposeOptionsType.add(loanpurpose); loanPurposeOptionsTypeNames.add(loanPurposeOptionsTypesObject.optString("name")); loanPurposeNameIdHashMap.put(loanpurpose.getName(), loanpurpose.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> loanPTypeAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, loanPurposeOptionsTypeNames); loanPTypeAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_loan_purpose.setAdapter(loanPTypeAdapter); sp_loan_purpose.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { loanPurposeId = loanPurposeNameIdHashMap.get(loanPurposeOptionsTypeNames.get(i)); Log.d("loanpurpose" + loanPurposeOptionsTypeNames.get(i), String.valueOf(loanPurposeId)); if (loanPurposeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_fund), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.basetechnology.s0.agentserver.field.StringField.java
public static Field fromJson(SymbolTable symbolTable, JSONObject fieldJson) { String type = fieldJson.optString("type").toLowerCase(); if (type == null || !type.equals("string")) return null; String name = fieldJson.has("name") ? fieldJson.optString("name") : null; String label = fieldJson.has("label") ? fieldJson.optString("label") : null; String description = fieldJson.has("description") ? fieldJson.optString("description") : null; String defaultValue = fieldJson.has("default_value") ? fieldJson.optString("default_value") : null; int minLength = fieldJson.has("min_length") ? fieldJson.optInt("min_length") : 0; int maxLength = fieldJson.has("max_length") ? fieldJson.optInt("max_length") : 0; int nominalWidth = fieldJson.has("nominal_width") ? fieldJson.optInt("nominal_width") : 0; String validRegex = fieldJson.has("valid_regex") ? fieldJson.optString("valid_regex") : null; String compute = fieldJson.has("compute") ? fieldJson.optString("compute") : null; return new StringField(symbolTable, name, label, description, defaultValue, minLength, maxLength, nominalWidth, validRegex, compute); }
From source file:sh.calaba.driver.client.model.impl.WebViewImpl.java
public String getCurrentUrl() { JSONObject response = executeCalabashCommand(CalabashCommands.GET_WEBVIEW_URL); return response.optString("message"); }
From source file:com.example.protocol.PLAYER.java
public void fromJson(JSONObject jsonObject) throws JSONException { if (null == jsonObject) { return;/*from w w w .j a v a2s . c o m*/ } this.id = jsonObject.optInt("id"); this.name = jsonObject.optString("name"); this.location = jsonObject.optString("location"); this.followers_count = jsonObject.optInt("followers_count"); this.draftees_conut = jsonObject.optInt("draftees_conut"); this.likes_count = jsonObject.optInt("likes_count"); this.likes_receiced_count = jsonObject.optInt("likes_receiced_count"); this.rebounds_count = jsonObject.optInt("rebounds_count"); this.rebounds_received_count = jsonObject.optInt("rebounds_received_count"); this.url = jsonObject.optString("url"); this.avatar_url = jsonObject.optString("avatar_url"); this.username = jsonObject.optString("username"); this.twitter_screen_name = jsonObject.optString("twitter_screen_name"); this.website_url = jsonObject.optString("website_url"); this.drafted_by_player_id = jsonObject.optInt("drafted_by_player_id"); this.shots_count = jsonObject.optInt("shots_count"); this.following_count = jsonObject.optInt("following_count"); this.created_at = jsonObject.optString("created_at"); return; }
From source file:fr.cph.stock.android.activity.ErrorActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.error);// ww w .java 2s. c o m String msg = getIntent().getExtras().getString("data"); login = getIntent().getExtras().getString("login"); password = getIntent().getExtras().getString("password"); try { JSONObject json = new JSONObject(msg); error = (TextView) findViewById(R.id.error_message); error.setText(json.optString("error")); } catch (JSONException e) { Log.e(TAG, e.getMessage(), e); } Button button = (Button) findViewById(R.id.retry_button); button.setOnClickListener(new ErrorButtonOnClickListener(this, login, password)); EasyTracker.getInstance().setContext(this); }
From source file:fr.cph.stock.android.activity.ErrorActivity.java
public void displayError(JSONObject json) { error.setText(json.optString("error")); }
From source file:com.citrus.sdk.payment.PaymentOption.java
public static PaymentOption fromJSONObject(JSONObject walletObject) { PaymentOption paymentOption = null;/*from w ww .ja v a 2s.com*/ String type = walletObject.optString("type"); String name = walletObject.optString("name"); String token = walletObject.optString("token"); String cardHolderName = walletObject.optString("owner"); String expiry = walletObject.optString("expiryDate"); String cardNumber = walletObject.optString("number"); String cardScheme = walletObject.optString("scheme"); if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(token)) { if (TextUtils.equals("credit", type)) { paymentOption = new CreditCardOption(name, token, cardHolderName, cardNumber, CardScheme.getCardScheme(cardScheme), expiry); } else if (TextUtils.equals("debit", type)) { paymentOption = new DebitCardOption(name, token, cardHolderName, cardNumber, CardScheme.getCardScheme(cardScheme), expiry); } else { String bankName = walletObject.optString("bank"); paymentOption = new NetbankingOption(name, token, bankName); } } return paymentOption; }