List of usage examples for org.json JSONArray getString
public String getString(int index) throws JSONException
From source file:com.orange.oidc.secproxy_service.Token.java
public void fromToken(String token) { reset();//from w w w. ja va 2 s . c om if (token == null) return; try { JSONObject jObject = null; // try token as is try { jObject = new JSONObject(token); } catch (Exception e) { } // try to decode JWT if (jObject == null) { String ds = getJSON(token); if (ds != null) jObject = new JSONObject(ds); } if (jObject != null) { JSONArray names = jObject.names(); if (names != null) { for (int j = 0; j < names.length(); j++) { String name = names.getString(j); // Log.d("Token",name); setField(name, jObject.get(name)); } } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.orange.oidc.secproxy_service.Token.java
void setField(String name, Object object) { if (name == null || name.length() == 0) return;//from w w w . j av a2 s .c o m if (name.compareTo("iss") == 0) { iss = (String) object; } else if (name.compareTo("sub") == 0) { sub = (String) object; } else if (name.compareTo("aud") == 0) { JSONArray jArray = (JSONArray) object; aud = ""; for (int i = 0; i < jArray.length(); i++) { try { aud += jArray.getString(i) + " "; } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else if (name.compareTo("jti") == 0) { jti = (String) object; } else if (name.compareTo("exp") == 0) { exp = getIntAsString(object); } else if (name.compareTo("iat") == 0) { iat = getIntAsString(object); } else if (name.compareTo("auth_time") == 0) { auth_time = getIntAsString(object); } else if (name.compareTo("nonce") == 0) { nonce = (String) object; } else if (name.compareTo("at_hash") == 0) { at_hash = (String) object; } else if (name.compareTo("acr") == 0) { acr = (String) object; } else if (name.compareTo("amr") == 0) { amr = (String) object; } else if (name.compareTo("azp") == 0) { azp = (String) object; } else if (name.compareTo("tim_app_key") == 0) { tak = (String) object; } }
From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java
/** * Universal privatemethod for parsing JSON array. * // w w w . ja v a 2s . co m * @param sense - JSONArray to be parsed */ private List<String> parseOneJSONArray(JSONArray sense) { if (sense == null) { return null; } List<String> temp = new ArrayList<>(); for (int k = 0; k < sense.length(); k++) { String value; try { value = sense.getString(k); temp.add(value); } catch (JSONException e) { Log.w(LOG_TAG, "getting parseOneSense() expression failed: " + e.toString()); e.printStackTrace(); } } return temp; }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get String array from jsonObject/*from w w w. j a va 2s . co m*/ * * @param jsonObject * @param key * @param defaultValue * @return <ul> * <li>if jsonObject is null, return defaultValue</li> * <li>if key is null or empty, return defaultValue</li> * <li>if {@link JSONObject#getJSONArray(String)} exception, return defaultValue</li> * <li>if {@link JSONArray#getString(int)} exception, return defaultValue</li> * <li>return string array</li> * </ul> */ public static String[] getStringArray(JSONObject jsonObject, String key, String[] defaultValue) { if (jsonObject == null || StringUtils.isEmpty(key)) { return defaultValue; } try { JSONArray statusArray = jsonObject.getJSONArray(key); if (statusArray != null) { String[] value = new String[statusArray.length()]; for (int i = 0; i < statusArray.length(); i++) { value[i] = statusArray.getString(i); } return value; } } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return defaultValue; } return defaultValue; }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get String list from jsonObject// ww w . j a va2 s .com * * @param jsonObject * @param key * @param defaultValue * @return <ul> * <li>if jsonObject is null, return defaultValue</li> * <li>if key is null or empty, return defaultValue</li> * <li>if {@link JSONObject#getJSONArray(String)} exception, return defaultValue</li> * <li>if {@link JSONArray#getString(int)} exception, return defaultValue</li> * <li>return string array</li> * </ul> */ public static List<String> getStringList(JSONObject jsonObject, String key, List<String> defaultValue) { if (jsonObject == null || StringUtils.isEmpty(key)) { return defaultValue; } try { JSONArray statusArray = jsonObject.getJSONArray(key); if (statusArray != null) { List<String> list = new ArrayList<String>(); for (int i = 0; i < statusArray.length(); i++) { list.add(statusArray.getString(i)); } return list; } } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return defaultValue; } return defaultValue; }
From source file:org.acaro.graffiti.processing.GraffitiReader.java
@Override public BasicVertex<Text, IntWritable, Text, Message> getCurrentVertex() throws IOException, InterruptedException { Vertex vertex = new Vertex(); Text line = getRecordReader().getCurrentValue(); try {/*from w w w. j a va2s .co m*/ JSONArray jsonVertex = new JSONArray(line.toString()); vertex.setVertexId(new Text(jsonVertex.getString(0))); vertex.setMsgList(msgList); JSONArray jsonEdgeArray = jsonVertex.getJSONArray(1); for (int i = 0; i < jsonEdgeArray.length(); ++i) { JSONArray jsonEdge = jsonEdgeArray.getJSONArray(i); vertex.addEdge(new Text(jsonEdge.getString(1)), new Text(jsonEdge.getString(0))); } } catch (JSONException e) { throw new IllegalArgumentException("next: Couldn't get vertex from line " + line, e); } return vertex; }
From source file:edu.cwru.apo.Home.java
public void onRestRequestComplete(Methods method, JSONObject result) { if (method == Methods.phone) { if (result != null) { try { String requestStatus = result.getString("requestStatus"); if (requestStatus.compareTo("success") == 0) { SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE) .edit();/* ww w . j a v a2s . c o m*/ editor.putLong("updateTime", result.getLong("updateTime")); editor.commit(); int numbros = result.getInt("numBros"); JSONArray caseID = result.getJSONArray("caseID"); JSONArray first = result.getJSONArray("first"); JSONArray last = result.getJSONArray("last"); JSONArray phone = result.getJSONArray("phone"); JSONArray family = result.getJSONArray("family"); ContentValues values; for (int i = 0; i < numbros; i++) { values = new ContentValues(); values.put("_id", caseID.getString(i)); values.put("first", first.getString(i)); values.put("last", last.getString(i)); values.put("phone", phone.getString(i)); values.put("family", family.getString(i)); database.replace("phoneDB", null, values); } } else if (requestStatus.compareTo("timestamp invalid") == 0) { Toast msg = Toast.makeText(this, "Invalid timestamp. Please try again.", Toast.LENGTH_LONG); msg.show(); } else if (requestStatus.compareTo("HMAC invalid") == 0) { Auth.loggedIn = false; Toast msg = Toast.makeText(this, "You have been logged out by the server. Please log in again.", Toast.LENGTH_LONG); msg.show(); finish(); } else { Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG); msg.show(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } else if (method == Methods.checkAppVersion) { if (result != null) { try { String requestStatus = result.getString("requestStatus"); if (requestStatus.compareTo("success") == 0) { String appVersion = result.getString("version"); String appDate = result.getString("date"); final String appUrl = result.getString("url"); PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0); ; if (appVersion.compareTo(pinfo.versionName) != 0) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Upgrade"); builder.setMessage("Update available, ready to upgrade?"); builder.setIcon(R.drawable.icon); builder.setCancelable(false); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent promptInstall = new Intent("android.intent.action.VIEW", Uri.parse("https://apo.case.edu:8090/app/" + appUrl)); startActivity(promptInstall); } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } else { Toast msg = Toast.makeText(this, "No updates found", Toast.LENGTH_LONG); msg.show(); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
From source file:com.shenyun.statistics.plugins.ShenYunDataPlugin.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArray of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return True when the action was valid, false otherwise. *///from w ww . j a v a 2s. c om public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("init")) { ShenYunCordovaStatistics.init(activity, args.getString(0), args.getString(1), args.getString(2)); } else if (action.equals("setDevMode")) { ShenYunCordovaStatistics.setDevMode(activity, args.getBoolean(0)); } else if (action.equals("onPageStart")) { ShenYunCordovaStatistics.onResume(activity, args.getString(0)); } else if (action.equals("onPageEnd")) { ShenYunCordovaStatistics.onPause(activity, args.getString(0)); } else if (action.equals("onEvent")) { ShenYunCordovaStatistics.onEvent(activity, args.getString(0), args.getString(1), args.getString(2), args.getString(3)); } else if (action.equals("setUserId")) { ShenYunCordovaStatistics.setUserId(activity, args.getString(0)); } else { return false; } // Only alert and confirm are async. callbackContext.success(); return true; }
From source file:edu.txstate.dmlab.clusteringwiki.sources.AbsSearchResultCol.java
/** * Creates a collection of results from JSON response * Note that firstPosition must be set before adding * results as result ids depend on that value. * @param res// w w w. j ava2 s . com */ public AbsSearchResultCol(JSONObject res) { if (res == null) return; JSONObject search = null; try { search = res.getJSONObject("search"); JSONArray errors = search.getJSONArray("errors"); if (errors != null && errors.length() > 0) { for (int i = 0; i < errors.length(); i++) { String error = errors.getString(i); addError("AbS API exception: " + error); } return; } } catch (JSONException e) { addError("AbS API exception: " + e.getMessage()); } try { totalResults = search.getInt("totalResults"); firstPosition = search.getInt("firstPosition"); JSONArray j = search.getJSONArray("results"); returnedCount = j.length(); for (int i = 0; i < j.length(); i++) { ICWSearchResult r = new AbsSearchResult(j.getJSONObject(i)); r.setIndex(i); addResult(r); } } catch (JSONException e) { addError("Could not retrieve AbS results: " + e.getMessage()); } }
From source file:re.notifica.cordova.NotificarePlugin.java
/** * Register a device and (optionally) its user to Notificare * @param args// w ww .j a v a2s.com * @param callbackContext * @throws JSONException */ protected void registerDevice(JSONArray args, final CallbackContext callbackContext) { Log.d(TAG, "REGISTER"); try { String deviceId = args.getString(0); String userId = null; String userName = null; if (args.length() == 2) { userId = args.getString(1); } if (args.length() == 3) { userId = args.getString(1); userName = args.getString(2); } Notificare.shared().registerDevice(deviceId, userId, userName, new NotificareCallback<String>() { @Override public void onSuccess(String result) { Notificare.shared().setDeviceId(result); if (callbackContext == null) { return; } callbackContext.success(); } @Override public void onError(NotificareError error) { if (callbackContext == null) { return; } callbackContext.error(error.getLocalizedMessage()); } }); } catch (JSONException e) { callbackContext.error("JSON parse error"); } }