Java Code Examples for org.json.JSONArray#getBoolean()
The following examples show how to use
org.json.JSONArray#getBoolean() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSONOpUtils.java From Alibaba-Android-Certification with MIT License | 6 votes |
/** * 从JSONArray中获取String对象 * @param jarr 源JSONArray * @param index 对象索引 * @return 异常返回null */ public static <T> Object getObject(JSONArray jarr,int index,Class<T> clazz){ if(jarr==null) return null; try{ if(TypeValidation.isInteger(clazz)||TypeValidation.isNumber(clazz)){ return jarr.getInt(index); }else if(TypeValidation.isString(clazz)){ return jarr.getString(index); }else if(TypeValidation.isBoolean(clazz)){ return jarr.getBoolean(index); }else if(TypeValidation.isLong(clazz)){ return jarr.getLong(index); }else if(TypeValidation.isDouble(clazz)){ return jarr.getDouble(index); } return jarr.get(index); }catch(Exception ex){ LogCat.e("JSONOpUtils","getObject",ex); return null; } }
Example 2
Source File: SendingTask.java From IoTgo_Android_App with MIT License | 6 votes |
@Override public void execute(JSONArray args, CallbackContext ctx) { try { int id = args.getInt(0); String data = args.getString(1); boolean binaryString = args.getBoolean(2); Connection conn = _map.get(id); if (conn != null) { if (binaryString) { byte[] binary = Base64.decode(data, Base64.NO_WRAP); conn.sendMessage(binary, 0, binary.length); } else { conn.sendMessage(data); } } } catch (Exception e) { ctx.error("send"); } }
Example 3
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private static void onFlag(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, JSONException { // Star/unstar message DB db = DB.getInstance(context); if (!ifolder.getPermanentFlags().contains(Flags.Flag.FLAGGED)) { db.message().setMessageFlagged(message.id, false); db.message().setMessageUiFlagged(message.id, false, null); return; } boolean flagged = jargs.getBoolean(0); if (message.flagged.equals(flagged)) return; Message imessage = ifolder.getMessageByUID(message.uid); if (imessage == null) throw new MessageRemovedException(); imessage.setFlag(Flags.Flag.FLAGGED, flagged); db.message().setMessageFlagged(message.id, flagged); }
Example 4
Source File: RippleChartsAPI.java From RipplePower with Apache License 2.0 | 6 votes |
private static ArrayList<RippleItem> jsonToItems(Object o) { if (o != null && o instanceof JSONArray) { JSONArray arrays = (JSONArray) o; ArrayList<RippleItem> list = new ArrayList<RippleItem>(arrays.length() - 1); for (int i = 0; i < arrays.length(); i++) { RippleItem item = new RippleItem(); JSONArray obj = arrays.getJSONArray(i); int idx = 0; item.startTime = obj.getString(idx++); item.baseVolume = obj.getDouble(idx++); item.counterVolume = obj.getDouble(idx++); item.count = obj.getDouble(idx++); item.open = obj.getDouble(idx++); item.high = obj.getDouble(idx++); item.low = obj.getDouble(idx++); item.close = obj.getDouble(idx++); item.vwap = obj.getDouble(idx++); item.openTime = obj.getString(idx++); item.closeTime = obj.getString(idx++); item.partial = obj.getBoolean(idx++); list.add(item); } return list; } return null; }
Example 5
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 6 votes |
private static void onAnswered(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, IMAPFolder ifolder) throws MessagingException, JSONException { // Mark message (un)answered DB db = DB.getInstance(context); if (!ifolder.getPermanentFlags().contains(Flags.Flag.ANSWERED)) { db.message().setMessageAnswered(message.id, false); db.message().setMessageUiAnswered(message.id, false); return; } boolean answered = jargs.getBoolean(0); if (message.answered.equals(answered)) return; // This will be fixed when moving the message if (message.uid == null) return; Message imessage = ifolder.getMessageByUID(message.uid); if (imessage == null) throw new MessageRemovedException(); imessage.setFlag(Flags.Flag.ANSWERED, answered); db.message().setMessageAnswered(message.id, answered); }
Example 6
Source File: AssetRequest.java From mdw with Apache License 2.0 | 6 votes |
/** * For parsing attribute array value (order-dependent). */ public Parameter(JSONArray jsonArray) { if (jsonArray.length() < 2) throw new JSONException("Missing required values: 'name', 'type'"); this.name = jsonArray.getString(0); this.type = ParameterType.valueOf(jsonArray.getString(1)); for (int i = 2; i < jsonArray.length(); i++) { switch (i) { case 2: this.required = jsonArray.getBoolean(i); break; case 3: this.description = jsonArray.getString(i); break; case 4: this.dataType = jsonArray.getString(i).replace('/', '.'); if (this.dataType.endsWith(".java") || this.dataType.endsWith(".kt")) this.dataType = this.dataType.substring(0, this.dataType.lastIndexOf(".")); break; } } }
Example 7
Source File: JSONHelper.java From libcommon with Apache License 2.0 | 6 votes |
public static long optLong(final JSONArray payload, final int index, final long defaultValue) { long result = defaultValue; if (payload.length() > index) { try { result = payload.getLong(index); } catch (final JSONException e) { try { result = Long.parseLong(payload.getString(index)); } catch (final Exception e1) { try { result = payload.getBoolean(index) ? 1 :0; } catch (final Exception e2) { Log.w(TAG, e2); } } } } return result; }
Example 8
Source File: VolumeControl.java From reader with MIT License | 5 votes |
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { boolean actionState = true; context = cordova.getActivity().getApplicationContext(); manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); if (SET.equals(action)) { try { //Get the volume value to set int volume = getVolumeToSet(args.getInt(0)); boolean play_sound; if(args.length() > 1 && !args.isNull(1)) { play_sound = args.getBoolean(1); } else { play_sound = true; } //Set the volume manager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, (play_sound ? AudioManager.FLAG_PLAY_SOUND : 0)); callbackContext.success(); } catch (Exception e) { LOG.d(TAG, "Error setting volume " + e); actionState = false; } } else if(GET.equals(action)) { //Get current system volume int currVol = getCurrentVolume(); String strVol= String.valueOf(currVol); callbackContext.success(strVol); LOG.d(TAG, "Current Volume is " + currVol); } else { actionState = false; } return actionState; }
Example 9
Source File: Bundle.java From unleashed-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public boolean[] getBooleanArray( String key ) { try { JSONArray array = data.getJSONArray( key ); int length = array.length(); boolean[] result = new boolean[length]; for (int i=0; i < length; i++) { result[i] = array.getBoolean( i ); } return result; } catch (JSONException e) { return null; } }
Example 10
Source File: WifiAdmin.java From cordova-plugin-wifi with MIT License | 5 votes |
private PluginResult executeEnableWifiAP(JSONArray inputs, CallbackContext callbackContext) { Log.w(LOGTAG, "executeEnableWifiAP"); boolean toEnable = true; try { toEnable = inputs.getBoolean( 0 ); } catch (JSONException e) { Log.w(LOGTAG, String.format("Got JSON Exception: %s", e.getMessage())); return new PluginResult(Status.JSON_EXCEPTION); } return null; }
Example 11
Source File: Bundle.java From shattered-pixel-dungeon with GNU General Public License v3.0 | 5 votes |
public boolean[] getBooleanArray( String key ) { try { JSONArray array = data.getJSONArray( key ); int length = array.length(); boolean[] result = new boolean[length]; for (int i=0; i < length; i++) { result[i] = array.getBoolean( i ); } return result; } catch (JSONException e) { Game.reportException(e); return null; } }
Example 12
Source File: Bundle.java From shattered-pixel-dungeon-gdx with GNU General Public License v3.0 | 5 votes |
public boolean[] getBooleanArray( String key ) { try { JSONArray array = data.getJSONArray( key ); int length = array.length(); boolean[] result = new boolean[length]; for (int i=0; i < length; i++) { result[i] = array.getBoolean( i ); } return result; } catch (JSONException e) { Game.reportException(e); return null; } }
Example 13
Source File: ParseTypes.java From cordova-plugin-app-launcher with MIT License | 5 votes |
public static boolean[] toBooleanArray(JSONArray arr) throws JSONException { int jsize = arr.length(); boolean[] exVal = new boolean[jsize]; for(int j=0; j < jsize; j++) { exVal[j] = arr.getBoolean(j); } return exVal; }
Example 14
Source File: Bundle.java From remixed-dungeon with GNU General Public License v3.0 | 5 votes |
@NotNull public boolean[] getBooleanArray(String key) { try { JSONArray array = data.getJSONArray(key); int length = array.length(); boolean[] result = new boolean[length]; for (int i = 0; i < length; i++) { result[i] = array.getBoolean(i); } return result; } catch (JSONException e) { return new boolean[0]; } }
Example 15
Source File: VolumeControl.java From reader with MIT License | 5 votes |
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { boolean actionState = true; context = cordova.getActivity().getApplicationContext(); manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); if (SET.equals(action)) { try { //Get the volume value to set int volume = getVolumeToSet(args.getInt(0)); boolean play_sound; if(args.length() > 1 && !args.isNull(1)) { play_sound = args.getBoolean(1); } else { play_sound = true; } //Set the volume manager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, (play_sound ? AudioManager.FLAG_PLAY_SOUND : 0)); callbackContext.success(); } catch (Exception e) { LOG.d(TAG, "Error setting volume " + e); actionState = false; } } else if(GET.equals(action)) { //Get current system volume int currVol = getCurrentVolume(); String strVol= String.valueOf(currVol); callbackContext.success(strVol); LOG.d(TAG, "Current Volume is " + currVol); } else { actionState = false; } return actionState; }
Example 16
Source File: VolumeControl.java From reader with MIT License | 5 votes |
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { boolean actionState = true; context = cordova.getActivity().getApplicationContext(); manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); if (SET.equals(action)) { try { //Get the volume value to set int volume = getVolumeToSet(args.getInt(0)); boolean play_sound; if(args.length() > 1 && !args.isNull(1)) { play_sound = args.getBoolean(1); } else { play_sound = true; } //Set the volume manager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, (play_sound ? AudioManager.FLAG_PLAY_SOUND : 0)); callbackContext.success(); } catch (Exception e) { LOG.d(TAG, "Error setting volume " + e); actionState = false; } } else if(GET.equals(action)) { //Get current system volume int currVol = getCurrentVolume(); String strVol= String.valueOf(currVol); callbackContext.success(strVol); LOG.d(TAG, "Current Volume is " + currVol); } else { actionState = false; } return actionState; }
Example 17
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private static void onFlag(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder) throws MessagingException, JSONException { // Star/unstar message DB db = DB.getInstance(context); boolean flagged = jargs.getBoolean(0); db.message().setMessageFlagged(message.id, flagged); }
Example 18
Source File: Core.java From FairEmail with GNU General Public License v3.0 | 5 votes |
private static void onSeen(Context context, JSONArray jargs, EntityFolder folder, EntityMessage message, POP3Folder ifolder) throws JSONException { // Mark message (un)seen DB db = DB.getInstance(context); boolean seen = jargs.getBoolean(0); db.message().setMessageUiSeen(folder.id, seen); }
Example 19
Source File: VolumeControl.java From reader with MIT License | 5 votes |
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { boolean actionState = true; context = cordova.getActivity().getApplicationContext(); manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); if (SET.equals(action)) { try { //Get the volume value to set int volume = getVolumeToSet(args.getInt(0)); boolean play_sound; if(args.length() > 1 && !args.isNull(1)) { play_sound = args.getBoolean(1); } else { play_sound = true; } //Set the volume manager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, (play_sound ? AudioManager.FLAG_PLAY_SOUND : 0)); callbackContext.success(); } catch (Exception e) { LOG.d(TAG, "Error setting volume " + e); actionState = false; } } else if(GET.equals(action)) { //Get current system volume int currVol = getCurrentVolume(); String strVol= String.valueOf(currVol); callbackContext.success(strVol); LOG.d(TAG, "Current Volume is " + currVol); } else { actionState = false; } return actionState; }
Example 20
Source File: BackgroundVideo.java From backgroundvideo with GNU General Public License v3.0 | 4 votes |
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { this.callbackContext = callbackContext; this.requestArgs = args; try { Log.d(TAG, "ACTION: " + action); if (ACTION_START_RECORDING.equalsIgnoreCase(action)) { boolean recordAudio = args.getBoolean(2); List<String> permissions = new ArrayList<String>(); if (!cordova.hasPermission(android.Manifest.permission.CAMERA)) { permissions.add(android.Manifest.permission.CAMERA); } if (recordAudio && !cordova.hasPermission(android.Manifest.permission.RECORD_AUDIO)) { permissions.add(android.Manifest.permission.RECORD_AUDIO); } if (permissions.size() > 0) { cordova.requestPermissions(this, START_REQUEST_CODE, permissions.toArray(new String[0])); return true; } Start(this.requestArgs); return true; } if (ACTION_STOP_RECORDING.equalsIgnoreCase(action)) { Stop(); return true; } callbackContext.error(TAG + ": INVALID ACTION"); return false; } catch (Exception e) { Log.e(TAG, "ERROR: " + e.getMessage(), e); callbackContext.error(TAG + ": " + e.getMessage()); } return true; }