List of usage examples for org.json JSONObject getBoolean
public boolean getBoolean(String key) throws JSONException
From source file:eu.sathra.io.IO.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private Object getValue(JSONObject jObj, String param, Class<?> clazz) throws ArrayIndexOutOfBoundsException, IllegalArgumentException, Exception { try {/* w w w . jav a2 s . c o m*/ if (clazz.equals(String.class)) { return jObj.getString(param); } else if (clazz.equals(int.class)) { return jObj.getInt(param); } else if (clazz.equals(long.class)) { return jObj.getLong(param); } else if (clazz.equals(float.class)) { return (float) jObj.getDouble(param); } else if (clazz.equals(double.class)) { return jObj.getDouble(param); } else if (clazz.equals(boolean.class)) { return jObj.getBoolean(param); } else if (mAdapters.containsKey(clazz)) { return mAdapters.get(clazz).load(param, jObj); } else if (clazz.isEnum()) { return Enum.valueOf((Class<? extends Enum>) clazz, jObj.getString(param)); } else if (clazz.isArray()) { return getValue(jObj.getJSONArray(param), clazz.getComponentType()); } else { return load(jObj.getJSONObject(param), clazz); } } catch (JSONException e) { return null; } finally { jObj.remove(param); } }
From source file:org.androidsoft.games.memory.kids.model.Tile.java
/** * Constructor from a JSON object//from w w w .j ava 2s.c om */ Tile(JSONObject object) { try { mFound = object.getBoolean(ATTR_FOUND); mSelected = object.getBoolean(ATTR_SELECTED); mResId = object.getInt(ATTR_RESID); } catch (JSONException ex) { Logger.getLogger(Tile.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitBranchTest.java
static JSONObject getCurrentBranch(JSONObject branches) throws JSONException { JSONArray branchesArray = branches.getJSONArray(ProtocolConstants.KEY_CHILDREN); for (int i = 0; i < branchesArray.length(); i++) { JSONObject branch = branchesArray.getJSONObject(i); if (branch.getBoolean(GitConstants.KEY_BRANCH_CURRENT)) return branch; }/* w w w . java2 s .co m*/ return null; }
From source file:hongik.android.project.best.ReviewDetailActivity.java
public void drawReview() { String query = "func=reviewdetail" + "&cid=" + cid + "&license=" + license; DBConnector conn = new DBConnector(query); conn.start();/*from ww w. ja v a 2 s .com*/ try { conn.join(); JSONObject jsonResult = conn.getResult(); boolean result = jsonResult.getBoolean("result"); if (!result) { Toast.makeText(this, "Can not bring data", Toast.LENGTH_SHORT).show(); return; } JSONObject json = jsonResult.getJSONArray("values").getJSONObject(0); ((TextViewPlus) findViewById(R.id.reviewdetail_title)).setText(json.getString("SNAME")); ((TextViewPlus) findViewById(R.id.reviewdetail_address)).setText(json.getString("ADDR")); ((TextViewPlus) findViewById(R.id.reviewdetail_author)).setText(cid); ((RatingBar) findViewById(R.id.reviewdetail_grade)) .setRating(Float.parseFloat(json.getString("GRADE"))); ((EditTextPlus) findViewById(R.id.reviewdetail_text)).setText(json.getString("NOTE")); ((TextViewPlus) findViewById(R.id.reviewdetail_date)).setText(json.getString("DAY")); } catch (Exception ex) { } }
From source file:fr.bde_eseo.eseomega.lacommande.model.DetailedItem.java
public DetailedItem(JSONObject obj, int idcmd) throws JSONException { super(obj.getString("resume"), obj.getInt("status"), obj.getDouble("price"), obj.getString("datetime"), idcmd, obj.getInt("modcmd"), obj.getString("strcmd"), true); instructions = obj.getString("instructions"); imgUrl = obj.getString("imgurl"); idlydia = obj.getInt("idlydia"); paidbefore = obj.getInt("paidbefore") == 1; lydiaEnabled = obj.getBoolean("lydia_enabled"); }
From source file:eu.codeplumbers.cosi.services.CosiSmsService.java
private List<Sms> getRemoteMessages() { allSms.clear();/*from www.j a v a 2 s . c om*/ URL urlO = null; try { urlO = new URL(designUrl); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoInput(true); conn.setRequestMethod("POST"); // read the response int status = conn.getResponseCode(); InputStream in = null; if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { in = conn.getErrorStream(); } else { in = conn.getInputStream(); } StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONArray jsonArray = new JSONArray(result); if (jsonArray != null) { if (jsonArray.length() == 0) { EventBus.getDefault() .post(new SmsSyncEvent(SYNC_MESSAGE, "Your Cozy has no Text messages stored.")); Sms.setAllUnsynced(); } else { for (int i = 0; i < jsonArray.length(); i++) { mBuilder.setProgress(jsonArray.length(), i, false); mNotifyManager.notify(notification_id, mBuilder.build()); EventBus.getDefault() .post(new SmsSyncEvent(SYNC_MESSAGE, getString(R.string.lbl_sms_status_read_cozy))); JSONObject smsJson = jsonArray.getJSONObject(i).getJSONObject("value"); Sms sms = Sms.getBySystemIdAddressAndBody(smsJson.get("systemId").toString(), smsJson.getString("address"), smsJson.getString("body")); if (sms == null) { sms = new Sms(smsJson); } else { sms.setRemoteId(smsJson.getString("_id")); sms.setSystemId(smsJson.getString("systemId")); sms.setAddress(smsJson.getString("address")); sms.setBody(smsJson.getString("body")); if (smsJson.has("readState")) { sms.setReadState(smsJson.getBoolean("readState")); } sms.setDateAndTime(smsJson.getString("dateAndTime")); sms.setType(smsJson.getInt("type")); } sms.save(); allSms.add(sms); } } } else { errorMessage = "Failed to parse API response"; EventBus.getDefault().post(new SmsSyncEvent(SERVICE_ERROR, "Failed to parse API response")); } in.close(); conn.disconnect(); } catch (MalformedURLException e) { e.printStackTrace(); errorMessage = e.getLocalizedMessage(); } catch (ProtocolException e) { errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } catch (IOException e) { errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } catch (JSONException e) { errorMessage = e.getLocalizedMessage(); e.printStackTrace(); } return allSms; }
From source file:com.funzio.pure2D.particles.nova.vo.AnimatorVO.java
public AnimatorVO(final JSONObject json) throws JSONException { super(json);/*from w w w. j a va2 s . co m*/ name = json.optString("name"); type = json.optString("type"); if (json.has("accumulating")) { accumulating = json.getBoolean("accumulating"); } loop_mode = json.optString("loop_mode"); loop_count = NovaVO.getListInt(json, "loop_count"); start_delay = NovaVO.getListInt(json, "start_delay"); lifespan = NovaVO.getListInt(json, "lifespan"); }
From source file:mp.teardrop.Song.java
static Song fromJsonObject(JSONObject jsonBourne) { try {// www . j a v a2s . c o m Song song = new Song(jsonBourne.getBoolean("isCloudSong"), jsonBourne.getString("path"), jsonBourne.getString("title"), jsonBourne.getString("album"), jsonBourne.getString("artist"), jsonBourne.getInt("trackNumber")); if (song.isCloudSong) { song.id = -1337; song.albumId = -1337; song.artistId = -1337; song.dbPath = jsonBourne.getString("dbPath"); song.rgTrack = //TODO: make sure there isn't any loss of precision jsonBourne.has("rgTrack") ? new Float(jsonBourne.getDouble("rgTrack")) : null; song.rgAlbum = jsonBourne.has("rgAlbum") ? new Float(jsonBourne.getDouble("rgAlbum")) : null; } else { song.id = jsonBourne.getLong("id"); song.artistId = jsonBourne.getLong("artistId"); song.albumId = jsonBourne.getLong("albumId"); song.dbPath = null; } return song; } catch (JSONException e) { return null; } }
From source file:info.papdt.blacklight.api.attitudes.AttitudesApi.java
public static boolean cancelLike(long id) { WeiboParameters params = new WeiboParameters(); params.put("id", id); try {/*from ww w . j a v a2 s .co m*/ JSONObject json = request(Constants.ATTITUDE_DESTROY, params, HTTP_POST); if (json.getBoolean("result")) { return true; } } catch (Exception e) { return false; } return false; }
From source file:com.weibo.net.Weibo.java
/** * /*from w w w .ja v a 2s .c o m*/ * JSON status * @throws WeiboException */ private List<Status> getStatusList(String content) throws WeiboException { List<Status> statuses = new ArrayList<Status>(); try { // content = publicTimeline(weibo, Weibo.APP_KEY, since_id, max_id, count, base_app); JSONArray jarray = new JSONArray(content); for (int i = 0; i < jarray.length(); i++) { // Status status = new Status(); JSONObject json = jarray.getJSONObject(i); // status.setBmiddle_pic(json.getString("bmiddle_pic")); status.setCreated_at(new Date(json.getString("created_at"))); status.setFavorited(json.getBoolean("favorited")); status.setId(json.getLong("id")); //Long String if (!json.isNull("in_reply_to_screen_name")) status.setIn_reply_to_screen_name(json.getString("in_reply_to_screen_name")); else status.setIn_reply_to_screen_name(json.getString(null)); if (!json.isNull("in_reply_to_status_id")) status.setIn_reply_to_status_id(json.getString("in_reply_to_status_id")); else status.setIn_reply_to_status_id(json.getString(null)); if (!json.isNull("in_reply_to_user_id")) status.setIn_reply_to_user_id(json.getString("in_reply_to_user_id")); else status.setIn_reply_to_user_id(json.getString(null)); // status.setOriginal_pic(json.getString("original_pic")); status.setSource(json.getString("source")); // status.setRetweetedStatus((Status) json.get("retweeted_status")); if (!json.isNull("retweeted_status")) { String retweeted_rlt = json.getString("retweeted_status"); Status retweeted_status = getStatus(retweeted_rlt); status.setRetweetedStatus(retweeted_status); } status.setText(json.getString("text")); // status.setThumbnail_pic(json.getString("thumbnail_pic")); status.setTruncated(json.getBoolean("truncated")); // status.setUser((User) json.get("user")); if (!json.isNull("user")) { String user_rlt = json.getString("user"); User user = getUser(user_rlt); status.setUser(user); } statuses.add(status); //Add in List<> } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return statuses; }