Android JSONArray - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android JSONArray class.

This code example shows how to use the following methods:getString, length
        int reqCode = 42;   //Hitchhiker?
        int maxMatches = 0;
        String prompt = "";
 
        try { 
            if (args.length() > 0) {
                // Request code - passed back to the caller on a successful operation 
                String temp = args.getString(0);
                reqCode = Integer.parseInt(temp);
            } 
            if (args.length() > 1) {
                // Maximum number of matches, 0 means the recognizer decides 
                String temp = args.getString(1);
                maxMatches = Integer.parseInt(temp);
            } 
            if (args.length() > 2) {
                // Optional text prompt 
                prompt = args.getString(2);
            } 
        } 

9
CodeRank
This code example shows how to use the following methods:getString
    @Override 
    public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {
        boolean actionValid = true;
        if (NOTIFY.equals(action)) {
            try { 
                String tag = data.getString(0);
                String title = data.getString(1);
                String body = data.getString(2);
                String flag = data.getString(3);
                Log.d("NotificationPlugin", "Notification: " + tag + ", " + title + ", " + body);
                int notificationFlag = getFlagValue(flag);
                showNotification(tag, title, body, notificationFlag);
            } catch (JSONException jsonEx) {
                Log.d("NotificationPlugin", "Got JSON Exception "
                        + jsonEx.getMessage());
                actionValid = false;
            } 
        } else if (CLEAR.equals(action)){
            try { 
                String tag = data.getString(0);

9
CodeRank
This code example shows how to use the following methods:getString, length
        int reqCode = 42;   //Hitchhiker?
        int maxMatches = 0;
        String prompt = "";
 
        try { 
            if (args.length() > 0) {
                // Request code - passed back to the caller on a successful operation 
                String temp = args.getString(0);
                reqCode = Integer.parseInt(temp);
            } 
            if (args.length() > 1) {
                // Maximum number of matches, 0 means the recognizer decides 
                String temp = args.getString(1);
                maxMatches = Integer.parseInt(temp);
            } 
            if (args.length() > 2) {
                // Optional text prompt 
                prompt = args.getString(2);
            } 
        } 

9
CodeRank
This code example shows how to use the following methods:getInt, getString
		this.name = name;
		this.location = location;
	} 
	 
	public TokenDef(JSONArray json) throws JSONException {
		this.name = json.getString(0);
		this.location = new Location("",json.getInt(1),json.getInt(2),json.getInt(3),json.getInt(4));
	} 
	 
	public Location getLocation() {
		return location;
	} 
	 
	public String getName() {
		return name;
	} 
	 
	public void move(int line, int column) {
		boolean allInSameLine = location.getStartLine() == location.getEndLine();
		this.location = new Location("", location.getStartLine() + line, location.getStartColumn() + column,
8
CodeRank
This code example shows how to use the following methods:getString, length
     * @param callback Callback 
     */ 
    public static void decrypt(JSONArray args, AsyncCallback<JSONArray> callback) {
        try {             
            // Get the arguments 
            String enc = args.getString(0);
            String key = args.getString(1);
            String sig = null;
            String pub = null;
            if (args.length() == 4) {
                sig = args.getString(2);
                pub = args.getString(3);
            } 
            Boolean ver = null;
             
            // Convert everything into byte arrays 
            byte[] encRaw = Base64.decode(enc, Base64.DEFAULT);
            byte[] keyRaw = Base64.decode(stripKey(key), Base64.DEFAULT);
 
            // Verify signature 
7
CodeRank
This code example shows how to use the following methods:getString
	@Override 
	public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
		if ("show".equals(action)) {
			String text = "Please wait";
			try { 
				text = args.getString(0);
			} catch (Exception e) {
				LOG.d("WaitingDialog", "Text parameter not valid, using default"); 
			} 
			showWaitingDialog(text);
			callbackContext.success();
			return true; 
		} else if ("hide".equals(action)) {
			hideWaitingDialog(); 
			callbackContext.success();
			return true; 
		} 
		return false; 
	} 
	 
7
CodeRank
This code example shows how to use the following methods:getJSONArray, length
             * themselves. We are interested in the second and third elements, both of which 
             * should be JSON arrays. The second element/array contains the suggestions and the 
             * third element contains the descriptions. Some search engines don't support 
             * suggestion descriptions so the third element is optional. 
             */ 
            JSONArray results = new JSONArray(content);
            JSONArray suggestions = results.getJSONArray(1);
            JSONArray descriptions = null;
            if (results.length() > 2) {
                descriptions = results.getJSONArray(2);
                // Some search engines given an empty array "[]" for descriptions instead of 
                // not including it in the response. 
                if (descriptions.length() == 0) {
                    descriptions = null;
                } 
            } 
            return new SuggestionsCursor(suggestions, descriptions);
        } catch (JSONException e) {
            Log.w(TAG, "Error", e);
        } 
7
CodeRank
This code example shows how to use the following methods:put
    simple1.put("boolean", true);
    simple1.put("string", "abc");
 
    array.put("boolean", true);
    array.put("string", "abc");
    JSONArray a = new JSONArray();
    a.put("a1");
    a.put("a2");
    a.put("a3");
    array.put("array", a);
 
  } 
 
  @Test 
  public void empty() throws JSONException { 
    Map<String, Object> decoded = new IOSCapabilities(empty).getRawCapabilities();
    Assert.assertTrue(decoded.isEmpty());
  } 
 
 
7
CodeRank
This code example shows how to use the following methods:getJSONObject
	@Override 
	public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
		if ("showEmailComposer".equals(action)) {
			 
			try { 
				JSONObject parameters = args.getJSONObject(0);
				if (parameters != null) {
					sendEmail(parameters);
				} 
			} catch (Exception e) {
 
			} 
			callbackContext.success();
			return true; 
		} 
		return false;  // Returning false results in a "MethodNotFound" error. 
	} 
 
	private void sendEmail(JSONObject parameters) {
		 
7
CodeRank
This code example shows how to use the following methods:length, put
        } 
    } 
     
    static public void append(JSONArray a, JSONObject element) {
        try { 
            a.put(a.length(), element);
        } catch (JSONException e) {
        } 
    } 
     
    static public void append(JSONArray a, Object element) {
        try { 
            a.put(a.length(), element);
        } catch (JSONException e) {
        } 
    } 
     
    static public void append(JSONArray a, int element) {
        try { 
            a.put(a.length(), element);
7
CodeRank

Related Android JSONArray Questions & Answers:

Other Android JSONArray Examples

24:						JSONObject jsonObj = new JSONObject(json);
25:						if (jsonObj != null) {
26:							JSONArray categories = jsonObj
27:									.getJSONArray("categories");						
28:

Read More

18:	
19:		// contacts JSONArray
20:		JSONArray contacts = null;
21:	
22:		// Hashmap for ListView

Read More

42:	
43:		// contacts JSONArray
44:		JSONArray contacts = null;
45:	
46:		// Hashmap for ListView

Read More

See Code Examples for Android JSONArray Methods: