Best code examples for Android JSONObject class (org.json.JSONObject)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android JSONObject class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Android JSONObject examples from Open Source projects
This code example shows how to use the following methods: getString, has
271:	JSONObject json = new JSONObject(response); 
-
275:	if (json.has("error")) { 
-
280:	if (json.has("error_code") && json.has("error_msg")) { 
281:	throw new FacebookError(json.getString("error_msg"), "", 
282:	Integer.parseInt(json.getString("error_code"))); 
-
284:	if (json.has("error_code")) { 
-
286:	Integer.parseInt(json.getString("error_code"))); 
-
288:	if (json.has("error_msg")) { 
289:	throw new FacebookError(json.getString("error_msg")); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: put
90:	JSONObject o = new JSONObject(); 
91:	o.put("code", "error"); 
92:	o.put("message", e.getMessage()); 
-
100:	o.put("stack", sw.toString()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getString, has
273:	JSONObject json = new JSONObject(response); 
-
277:	if (json.has("error")) { 
-
282:	if (json.has("error_code") && json.has("error_msg")) { 
283:	throw new FacebookError(json.getString("error_msg"), "", 
284:	Integer.parseInt(json.getString("error_code"))); 
-
286:	if (json.has("error_code")) { 
-
288:	Integer.parseInt(json.getString("error_code"))); 
-
290:	if (json.has("error_msg")) { 
291:	throw new FacebookError(json.getString("error_msg")); 
-
293:	if (json.has("error_reason")) { 
294:	throw new FacebookError(json.getString("error_reason")); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getString, optString
19:	model.setId(obj.optString("id")); 
20:	model.setThumbUrl(obj.getString("thumb")); 
21:	String url = obj.getString("large"); 
-
26:	url = obj.getString("url"); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getInt, has, isNull
92:	int top = obj.has("top") && !obj.isNull("top") ? obj.getInt("top") : 10; 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getBoolean, getString, has
158:	info.label = mObject.getString("label"); 
159:	info.callback = mObject.getString("action"); 
160:	if (mObject.has("icon")) { 
-
170:	info.disabled = mObject.getBoolean("disabled"); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getString, has
20:	JSONObject object = new JSONObject(json); 
21:	mThumbnailUrl = object.getString("thumbnail_url"); 
22:	mUrl = object.getString("url"); 
23:	if (object.has("embeddable_url")) { 
24:	mExpandedUrl = object.getString("embeddable_url"); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getString, has
266:	JSONObject json = new JSONObject(response); 
-
270:	if (json.has("error")) { 
-
275:	if (json.has("error_code") && json.has("error_msg")) { 
276:	throw new FacebookError(json.getString("error_msg"), "", 
277:	Integer.parseInt(json.getString("error_code"))); 
-
279:	if (json.has("error_code")) { 
-
281:	Integer.parseInt(json.getString("error_code"))); 
-
283:	if (json.has("error_msg")) { 
284:	throw new FacebookError(json.getString("error_msg")); 
-
286:	if (json.has("error_reason")) { 
287:	throw new FacebookError(json.getString("error_reason")); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: put
283:	JSONObject obj = new JSONObject(); 
-
285:	obj.put("magneticHeading", this.getHeading()); 
286:	obj.put("trueHeading", this.getHeading()); 
-
289:	obj.put("headingAccuracy", 0); 
290:	obj.put("timestamp", this.timeStamp); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getJSONObject, getString
22:	JSONObject jsonObj = new JSONObject(jsonMessage); 
23:	JSONObject data = jsonObj.getJSONObject("data"); 
-
25:	this.type = data.getString("type"); 
26:	this.body = data.getString("body"); 
Full Snippet Info
-10
CodeRank
This code example shows how to use the following methods: getString, has
256:	JSONObject json = new JSONObject(response); 
-
260:	if (json.has("error")) { 
-
264:	if (json.has("error_code") && json.has("error_msg")) { 
265:	throw new FacebookError(json.getString("error_msg"), "", Integer.parseInt(json.getString("error_code"))); 
-
267:	if (json.has("error_code")) { 
268:	throw new FacebookError("request failed", "", Integer.parseInt(json.getString("error_code"))); 
-
270:	if (json.has("error_msg")) { 
271:	throw new FacebookError(json.getString("error_msg")); 
-
273:	if (json.has("error_reason")) { 
274:	throw new FacebookError(json.getString("error_reason")); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
60:	JSONObject options = new JSONObject(); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getString
297:	JSONObject json = new JSONObject(jsonString); 
-
299:	String valueType = json.getString(JSON_VALUE_TYPE); 
-
365:	String charString = json.getString(JSON_VALUE); 
-
380:	bundle.putString(key, json.getString(JSON_VALUE)); 
-
392:	String enumType = json.getString(JSON_VALUE_ENUM_TYPE); 
-
396:	Enum<?> enumValue = Enum.valueOf(enumClass, json.getString(JSON_VALUE)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getString, has
253:	JSONObject json = new JSONObject(response); 
-
257:	if (json.has("error")) { 
-
262:	if (json.has("error_code") && json.has("error_msg")) { 
263:	throw new TwitterError(json.getString("error_msg"), "", 
-
266:	if (json.has("error_code")) { 
-
270:	if (json.has("error_msg")) { 
271:	throw new TwitterError(json.getString("error_msg")); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: put
274:	JSONObject r = new JSONObject(); 
-
276:	r.put("x", this.x); 
277:	r.put("y", this.y); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getJSONArray, getJSONObject, has, put
157:	if (root.has(fieldName)) { 
158:	newArrayStep = root.getJSONArray(fieldName); 
-
161:	root.put(fieldName, newArrayStep); 
-
168:	if (root.has(steps[currentStep])) { 
169:	newStep = root.getJSONObject(steps[currentStep]); 
-
172:	root.put(steps[currentStep], newStep); 
Full Snippet Info
9
CodeRank
This code example shows how to use the following methods: optString
37:	.replace(":x1", payload.optString("fromX")) 
38:	.replace(":y1", payload.optString("fromY")) 
39:	.replace(":x2", payload.optString("toX")) 
40:	.replace(":y2", payload.optString("toY")) 
41:	.replace(":duration", payload.optString("duration")); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: get, getInt, has, keys
51:	"}"; 
52:	String jsonStr2 = "{"+ 
53:	"\"maxReceivesPerSecond\":null" + 
-
83:	json = new JSONObject(jsonStr4); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString, optBoolean, optInt
25:	name = json.getString("name"); 
26:	setType(json.getString("type")); 
-
28:	version = json.optInt("version", 1); 
-
31:	dbIsPrimaryKey = json.optBoolean("is_primary_key", false); 
32:	dbIsId = json.optBoolean("is_id", false); 
-
35:	dbIsAutoincrement = json.optBoolean("is_autoincrement", false); 
-
43:	dbHasIndex = !dbIsPrimaryKey && json.optBoolean("is_index", false); 
-
45:	dbSkipBulkInsert = json.optBoolean("skip_bulk_insert", false); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: put
245:	JSONObject expected = new JSONObject(); 
-
248:	expected.put("inputs", inputs); 
-
250:	expected.put("query", query); 
-
252:	assertTrue("Generated JSON not as expected", JSONEquals.equals(expected, builder.toJSON())); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: put
33:	final JSONObject res = new JSONObject(); 
-
35:	res.put("height", d.getDisplayHeight()); 
-
40:	return getSuccessResult(res); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString, has, isNull
101:	JSONObject json = new JSONObject(responseBody); 
102:	if (!json.has("sessionId") || json.isNull("sessionId")) { 
-
105:	return new ExternalSessionKey(json.getString("sessionId")); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: optDouble, optInt, optLong, optString
17:	_completedIn = json.optDouble("completed_in"); 
18:	_maxId = json.optLong("max_id"); 
19:	_nextPage = json.optString("next_page"); 
20:	_page = json.optInt("page"); 
21:	_query = Utils.unescape(json.optString("query")); 
22:	_refreshUrl = json.optString("refresh_url"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: get, getInt
47:	JSONObject root = new JSONObject(response); 
48:	totalResults = root.getInt("totalResults"); 
49:	itemsPerPage = root.getInt("itemsPerPage"); 
50:	startIndex = root.getInt("startIndex"); 
51:	Object entry = root.get("entry"); 
-
55:	profileImages.add(new ProfileImage(obj)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString
12:	layerId = json.getString("layer_id"); 
13:	userId = json.getString("user_id"); 
14:	type = json.getString("type"); 
15:	name = json.getString("name"); 
16:	icon = json.getString("icon"); 
17:	description = json.getString("description"); 
18:	url = json.getString("url"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: put, toString
37:	JSONObject json = new JSONObject(); 
-
39:	json.put("I", mCallbackId); 
40:	json.put("M", mMethod); 
41:	json.put("A", mArgs); 
42:	json.put("H", mHubName); 
-
47:	return json.toString(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getJSONArray, getJSONObject
51:	import com.google.refine.model.Project; 
-
109:	JSONObject progress = JSONUtilities.getObject(config, "progress"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: put, toString
308:	JSONObject o = new JSONObject(); 
309:	o.put("sling:resourceType", "sakai/learningCapability"); 
310:	o.put("sakai:pov", pointOfView); 
311:	o.put("sakai:id", keyValue.trim() + "_" + column); 
312:	o.put("sakai:name", COLUMNS[column]); 
313:	o.put("sakai:capability", value.trim()); 
-
315:	fw.append(o.toString(4)); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getDouble, getString, has
69:	if (	jo.has("title") && 
70:	jo.has("lat") && 
71:	jo.has("lng") && 
72:	jo.has("elevation") 
-
76:	jo.getString("title"), 
77:	jo.getDouble("lat"), 
78:	jo.getDouble("lng"), 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInt, getJSONObject, getString
252:	JSONObject json = new JSONObject(new String(b)); 
-
254:	this.uuid = json.getString("uuid"); 
-
256:	JSONObject proto = json.getJSONObject("protocol"); 
-
302:	return p.getString("name").equals(protocolName) 
303:	&& (p.getInt("versionMajor") == versionMajor) 
304:	&& (p.getInt("versionMinor") >= versionMinor); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString, has
260:	JSONObject json = new JSONObject(response); 
-
264:	if (json.has("error")) { 
-
269:	if (json.has("error_code") && json.has("error_msg")) { 
-
273:	if (json.has("error_code")) { 
-
277:	if (json.has("error_msg")) { 
-
280:	if (json.has("error_reason")) { 
281:	throw new FacebookError(json.getString("error_reason")); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: getString, has
274:	JSONObject json = new JSONObject(response); 
-
278:	if (json.has("error")) { 
-
283:	if (json.has("error_code") && json.has("error_msg")) { 
284:	throw new FacebookError(json.getString("error_msg"), "", 
285:	Integer.parseInt(json.getString("error_code"))); 
-
287:	if (json.has("error_code")) { 
-
289:	Integer.parseInt(json.getString("error_code"))); 
-
291:	if (json.has("error_msg")) { 
292:	throw new FacebookError(json.getString("error_msg")); 
-
294:	if (json.has("error_reason")) { 
295:	throw new FacebookError(json.getString("error_reason")); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: put
16:	json = new JSONObject(); 
17:	json.put("status", status.code()); 
18:	json.put("value", status.message()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString, optString
23:	this.id = jsonPhoto.getString("id"); 
24:	this.owner = jsonPhoto.getString("owner"); 
25:	this.title = jsonPhoto.optString("title", ""); 
26:	this.server = jsonPhoto.getString("server"); 
27:	this.farm = jsonPhoto.getString("farm"); 
28:	this.secret = jsonPhoto.getString("secret"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: get, getInt
47:	JSONObject root = new JSONObject(response); 
48:	totalResults = root.getInt("totalResults"); 
49:	itemsPerPage = root.getInt("itemsPerPage"); 
50:	startIndex = root.getInt("startIndex"); 
51:	Object entry = root.get("entry"); 
-
55:	groups.add(new Group(obj)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInt, getString
23:	spellName = jobj.getString("spell_name"); 
24:	spellTitle = jobj.getString("spell_title"); 
25:	spellId = jobj.getInt("spell_id"); 
26:	imageURL = jobj.getString("image_url"); 
27:	amount = jobj.getInt("amount"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getInt, isNull, optString
37:	String elementId = payload.optString("element"); 
-
42:	if (!payload.isNull("element") && !elementId.equals("")) { 
-
49:	Point toPoint = new Point(fromPoint.getX() + payload.getInt("xoffset"), fromPoint.getY() + payload.getInt("yoffset")); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
254:	return new JSONObject(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: put
77:	JSONObject obj = new JSONObject(); 
78:	obj.put("javaClass", o.getClass().getName()); 
79:	obj.put("gid", eo.globalID()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString, has
133:	JSONObject json = new JSONObject(response); 
-
137:	if (json.has("error")) { 
-
142:	if (json.has("error_code") && json.has("error_msg")) { 
-
146:	if (json.has("error_code")) { 
-
150:	if (json.has("error_msg")) { 
-
153:	if (json.has("error_reason")) { 
154:	throw new GraphAPIError(json.getString("error_reason")); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString
17:	jsonObject =  new JSONObject(str); 
18:	String flag = jsonObject.getString("flag"); 
-
25:	message.setMsg(jsonObject.getString("msg")); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: put, toString
86:	JSONObject object = new JSONObject(); 
-
90:	object.put("is_solved", is_solved); 
91:	object.put("hints_used", hints_used); 
-
96:	String json_str = object.toString(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString, has, isNull
87:	String type = obj.getString(partitionTypeFieldName); 
-
93:	if (! obj.has(filterConfigFieldName) || obj.isNull(filterConfigFieldName)) 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: put
86:	JSONObject obj = new JSONObject(); 
-
90:	obj.put("time", time); 
91:	obj.put("tz", tz); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getJSONObject, has, isNull
82:	if (!json.isNull("serves_types")) { 
-
89:	if (!json.isNull("metros")) { 
90:	JSONObject jsonMetros = json.getJSONObject("metros"); 
91:	if (jsonMetros.has("group_of_lines")) { 
92:	d.metros.add(MetroDeparture.fromJson(jsonMetros)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: put
100:	JSONObject obj = new JSONObject(); 
-
102:	obj.put("javaClass", o.getClass().getName()); 
-
104:	obj.put("bytes", bytes); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: getString
17:	this.title = unescapeHtml(json.getString("titleNoFormatting")); 
18:	this.clickURL = json.getString("unescapedUrl"); 
19:	this.source = json.getString("publisher"); 
Full Snippet Info
7
CodeRank
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: