JSONObject has - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for JSONObject has method.

This code example shows how to use the following methods:getString, has
            throw new FacebookError("request failed");
        } 
        if (response.equals("true")) {
            response = "{value : true}";
        } 
        JSONObject json = new JSONObject(response);
 
        // errors set by the server are not consistent 
        // they depend on the method and endpoint 
        if (json.has("error")) {
            JSONObject error = json.getJSONObject("error");
            throw new FacebookError(
                    error.getString("message"), error.getString("type"), 0);
        } 
        if (json.has("error_code") && json.has("error_msg")) {
            throw new FacebookError(json.getString("error_msg"), "",
                    Integer.parseInt(json.getString("error_code")));
        } 
        if (json.has("error_code")) {
            throw new FacebookError("request failed", "",

9
CodeRank
This code example shows how to use the following methods:getString, has
            throw new FacebookError("request failed");
        } 
        if (response.equals("true")) {
            response = "{value : true}";
        } 
        JSONObject json = new JSONObject(response);
 
        // errors set by the server are not consistent 
        // they depend on the method and endpoint 
        if (json.has("error")) {
            JSONObject error = json.getJSONObject("error");
            throw new FacebookError(
                    error.getString("message"), error.getString("type"), 0);
        } 
        if (json.has("error_code") && json.has("error_msg")) {
            throw new FacebookError(json.getString("error_msg"), "",
                    Integer.parseInt(json.getString("error_code")));
        } 
        if (json.has("error_code")) {
            throw new FacebookError("request failed", "",

8
CodeRank
This code example shows how to use the following methods:getString, has
    public String mUrl;
    public String mExpandedUrl;
 
    public AdnMedia(String json) {
        try { 
            JSONObject object = new JSONObject(json);
            mThumbnailUrl = object.getString("thumbnail_url");
            mUrl = object.getString("url");
            if (object.has("embeddable_url")) {
                mExpandedUrl = object.getString("embeddable_url");
            } 
        } catch (JSONException e) {
            e.printStackTrace();
        } 
    } 
 
    @Override 
    public String toString() {
        JSONObject object = new JSONObject();
        try { 
8
CodeRank
This code example shows how to use the following methods:getInt, has, isNull
        writer.endArray();
        writer.endObject();
    } 
     
    static public TopList load(JSONObject obj) throws JSONException {
        int top = obj.has("top") && !obj.isNull("top") ? obj.getInt("top") : 10;
        TopList tl = new TopList(top);
         
        if (obj.has("list") && !obj.isNull("list")) {
            JSONArray a = obj.getJSONArray("list");
             
            tl.load(a);
        } 
        return tl;
    } 
     
    public void load(JSONArray a) throws JSONException {
        int length = a.length();
        for (int i = 0; i < length && _list.size() < _top; i++) {
            _list.add(a.getString(i));
8
CodeRank
This code example shows how to use the following methods:getBoolean, getString, has
		} 
	} 
 
	private MenuInfo parseInfo(JSONObject mObject) throws JSONException {
		MenuInfo info = new MenuInfo();
		info.label = mObject.getString("label");
		info.callback = mObject.getString("action");
		if (mObject.has("icon")) {
			String tmp_uri = mObject.getString("icon");
			// I don't expect this to work at all 
			try { 
				info.icon = getIcon(tmp_uri);
			} catch (IOException e) {
				// DO NOTHING, we just don't have a file here! 
			} 
		} 
		try { 
			info.disabled = mObject.getBoolean("disabled");
		} 
		// Catch the case when "enabled" is not defined 

8
CodeRank
This code example shows how to use the following methods:getString, has
            throw new FacebookError("request failed");
        } 
        if (response.equals("true")) {
            response = "{value : true}";
        } 
        JSONObject json = new JSONObject(response);
 
        // errors set by the server are not consistent 
        // they depend on the method and endpoint 
        if (json.has("error")) {
            JSONObject error = json.getJSONObject("error");
            throw new FacebookError(
                    error.getString("message"), error.getString("type"), 0);
        } 
        if (json.has("error_code") && json.has("error_msg")) {
            throw new FacebookError(json.getString("error_msg"), "",
                    Integer.parseInt(json.getString("error_code")));
        } 
        if (json.has("error_code")) {
            throw new FacebookError("request failed", "",

8
CodeRank
This code example shows how to use the following methods:getString, has, isNull
   * @param responseBody the response body to parse 
   * @return the extracted ExternalKey, or null if one was not found. 
   */ 
  public static ExternalSessionKey fromJsonResponseBody(String responseBody) {
    try { 
      JSONObject json = new JSONObject(responseBody);
      if (!json.has("sessionId") || json.isNull("sessionId")) {
        return null; 
      } 
      return new ExternalSessionKey(json.getString("sessionId"));
    } catch (JSONException e) {
      return null; 
    } 
  } 
   
  /** 
   * extract the external key from the server response for a selenium1 new session request. 
   * @param responseBody the response from the server 
   * @return the ExternalKey if it was present in the server's response. 
   * @throws NewSessionException in case the server didn't send back a success result. 
8
CodeRank
This code example shows how to use the following methods:getString, has
			throw new FacebookError("request failed");
		} 
		if (response.equals("true")) {
			response = "{value : true}";
		} 
		JSONObject json = new JSONObject(response);
 
		// errors set by the server are not consistent 
		// they depend on the method and endpoint 
		if (json.has("error")) {
			JSONObject error = json.getJSONObject("error");
			throw new FacebookError(error.getString("message"), error.getString("type"), 0);
		} 
		if (json.has("error_code") && json.has("error_msg")) {
			throw new FacebookError(json.getString("error_msg"), "", Integer.parseInt(json.getString("error_code")));
		} 
		if (json.has("error_code")) {
			throw new FacebookError("request failed", "", Integer.parseInt(json.getString("error_code")));
		} 
		if (json.has("error_msg")) {

8
CodeRank
This code example shows how to use the following methods:getString, has
            throw new TwitterError("request failed"); 
        } 
        if (response.equals("true")) {
            response = "{value : true}";
        } 
        JSONObject json = new JSONObject(response);
         
        // errors set by the server are not consistent 
        // they depend on the method and endpoint 
        if (json.has("error")) {
            JSONObject error = json.getJSONObject("error");
            throw new TwitterError( 
                    error.getString("message"), error.getString("type"), 0);
        } 
        if (json.has("error_code") && json.has("error_msg")) {
            throw new TwitterError(json.getString("error_msg"), "",
                    Integer.parseInt(json.getString("error_code")));
        } 
        if (json.has("error_code")) {
            throw new TwitterError("request failed", "", 

8
CodeRank
This code example shows how to use the following methods:getJSONArray, getJSONObject, has, put
10
CodeRank

Related JSONObject has Questions & Answers:

has Method Overview
Returns true if this object has a mapping for name.
See Code Examples for other Android JSONObject Methods: