Android JSONObject - 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 JSONObject class.

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
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: put
        if (response == null) {
            throw new ServletException("Response object can't be null"); 
        } 
     
        try { 
            JSONObject o = new JSONObject();
            o.put("code", "error");
            o.put("message", e.getMessage());
     
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
     
            o.put("stack", sw.toString());
     
            response.setCharacterEncoding("UTF-8");
            response.setHeader("Content-Type", "application/json");
            respond(response, o.toString());
        } catch (JSONException e1) {
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getString, optString
			.getSimpleName();
 
	public static GCAccountMediaModel parse(final JSONObject obj)
			throws JSONException { 
		final GCAccountMediaModel model = new GCAccountMediaModel();
		model.setId(obj.optString("id"));
		model.setThumbUrl(obj.getString("thumb"));
		String url = obj.getString("large");
		if (TextUtils.isEmpty(url) || url.equalsIgnoreCase("null")) {
			url = model.getThumbUrl();
		} 
		model.setLargeUrl(url);
		url = obj.getString("url");
		if (TextUtils.isEmpty(url) || url.equalsIgnoreCase("null")) {
			url = model.getLargeUrl();
		} 
		model.setUrl(url);
		return model;
	} 
 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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));
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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 { 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: put
     * Create the CompassHeading JSON object to be returned to JavaScript 
     * 
     * @return a compass heading 
     */ 
    private JSONObject getCompassHeading() throws JSONException {
        JSONObject obj = new JSONObject();
 
        obj.put("magneticHeading", this.getHeading());
        obj.put("trueHeading", this.getHeading());
        // Since the magnetic and true heading are always the same our and accuracy 
        // is defined as the difference between true and magnetic always return zero 
        obj.put("headingAccuracy", 0);
        obj.put("timestamp", this.timeStamp);
 
        return obj;
    } 
 
} 
Full Snippet Info
8
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getJSONObject, getString
	private String type;
	private String body;
	 
	public PushMessage(String jsonMessage) throws PreyException{
		try { 
			JSONObject jsonObj = new JSONObject(jsonMessage);
			JSONObject data = jsonObj.getJSONObject("data");
			this.event = jsonObj.getString("event");
			this.type = data.getString("type");
			this.body = data.getString("body");
		} catch (JSONException e) {
			throw new PreyException("Couldn't parse pushed json message"); 
		} 
		 
		 
	} 
	 
	public String getEvent() {
		return event;
	} 
Full Snippet Info
-10
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Android JSONObject Questions & Answers:

Other Android JSONObject Examples

1:	  JSONObject object = new JSONObject();
2:	  try {
3:	    object.put("name", "Jack Hack");
-
1:	  JSONObject object = new JSONObject();
2:	  try {
3:	    object.put("name", "Jack Hack");

Read More

22:				if (json != null) {
23:					try {
24:						JSONObject jsonObj = new JSONObject(json);
25:						if (jsonObj != null) {
26:							JSONArray categories = jsonObj
-
22:				if (json != null) {
23:					try {
24:						JSONObject jsonObj = new JSONObject(json);
25:						if (jsonObj != null) {
26:							JSONArray categories = jsonObj

Read More

31:		 * @param password
32:		 * */
33:		public JSONObject loginUser(String email, String password){
34:			// Building Parameters
35:			List<NameValuePair> params = new ArrayList<NameValuePair>();
-
37:			params.add(new BasicNameValuePair("email", email));
38:			params.add(new BasicNameValuePair("password", password));
39:			JSONObject json = jsonParser.getJSONFromUrl(loginURL, params);
40:			// return json
41:			// Log.e("JSON", json.toString());
-
49:		 * @param password
50:		 * */
51:		public JSONObject registerUser(String name, String email, String password){
52:			// Building Parameters
53:			List<NameValuePair> params = new ArrayList<NameValuePair>();
-
58:			
59:			// getting JSON Object
60:			JSONObject json = jsonParser.getJSONFromUrl(registerURL, params);
61:			// return json
62:			return json;

Read More

22:	
23:		static InputStream is = null;
24:		static JSONObject jObj = null;
25:		static String json = "";
26:	
-
30:		}
31:	
32:		public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {
33:	
34:			// Making HTTP request
-
68:			// try parse the string to a JSON object
69:			try {
70:				jObj = new JSONObject(json);			
71:			} catch (JSONException e) {
72:				Log.e("JSON Parser", "Error parsing data " + e.toString());

Read More

See Code Examples for Android JSONObject Methods: