List of usage examples for org.json JSONObject isNull
public boolean isNull(String key)
From source file:edu.mbl.jif.imaging.mmtiff.OMEMetadata.java
private void setOMEDetectorMetadata(JSONObject tags) throws JSONException { if (!tags.has("Core-Camera") || tags.isNull("Core-Camera")) { return;/*w w w. j av a2s.c o m*/ } String coreCam = tags.getString("Core-Camera"); String[] cameras; if (tags.has(coreCam + "-Physical Camera 1")) { //Multicam mode int numCams = 1; if (!tags.getString(coreCam + "-Physical Camera 3").equals("Undefined")) { numCams = 3; } else if (!tags.getString(coreCam + "-Physical Camera 2").equals("Undefined")) { numCams = 2; } cameras = new String[numCams]; for (int i = 0; i < numCams; i++) { cameras[i] = tags.getString(coreCam + "-Physical Camera " + (1 + i)); } } else { //Single camera mode cameras = new String[1]; cameras[0] = coreCam; } for (int detectorIndex = 0; detectorIndex < cameras.length; detectorIndex++) { String camera = cameras[detectorIndex]; String detectorID = MetadataTools.createLSID(camera); //Instrument index, detector index metadata_.setDetectorID(detectorID, 0, detectorIndex); if (tags.has(camera + "-Name") && !tags.isNull(camera + "-Name")) { metadata_.setDetectorManufacturer(tags.getString(camera + "-Name"), 0, detectorIndex); } if (tags.has(camera + "-CameraName") && !tags.isNull(camera + "-CameraName")) { metadata_.setDetectorModel(tags.getString(camera + "-CameraName"), 0, detectorIndex); } if (tags.has(camera + "-Offset") && !tags.isNull(camera + "-Offset")) { metadata_.setDetectorOffset(Double.parseDouble(tags.getString(camera + "-Offset")), 0, detectorIndex); } if (tags.has(camera + "-CameraID") && !tags.isNull(camera + "-CameraID")) { metadata_.setDetectorSerialNumber(tags.getString(camera + "-CameraID"), 0, detectorIndex); } } }
From source file:com.weibo.net.Weibo.java
private List<Comment> getComments(String content) throws WeiboException { List<Comment> comments = new ArrayList<Comment>(); try {//from ww w.j av a 2 s . co m JSONArray jarray = new JSONArray(content); for (int i = 0; i < jarray.length(); i++) { Comment comment = new Comment(); JSONObject json = jarray.getJSONObject(i); comment.setCreated_at(new Date(json.getString("created_at"))); // comment.setFavorited(json.getBoolean("favorited")); comment.setId(json.getLong("id")); // comment.setSource(json.getString("source")); // comment.setStatus((Status) json.get("retweeted_status")); comment.setStatus(getStatus(json.getString("status"))); comment.setText(json.getString("text")); // comment.setTruncated(json.getBoolean("truncated")); // comment.setUser((User) json.get("user")); // Log.e("Weibo_comment user", "Is NULL??"); if (!json.isNull("user")) { // Log.e("Weibo", "User is not null"); String user_rlt = json.getString("user"); User user = getUser(user_rlt); comment.setUser(user); // Log.e("ScreenName", user.getScreen_name()); } comments.add(comment); //Add in List<> } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return comments; }
From source file:com.weibo.net.Weibo.java
/** * /* ww w . java 2 s. c om*/ * 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; }
From source file:com.weibo.net.Weibo.java
/** * JSON status/* ww w. ja v a2 s. co m*/ * @throws WeiboException */ private Status getStatus(String content) throws WeiboException { Status status = new Status(); try { JSONObject json = new JSONObject(content); // status.setBmiddle_pic(json.getString("bmiddle_pic")); int length = content.split(":").length; for (int i = 0; i < length; i++) { // Log.e("getStatus", // content.split(":")[i]); } status.setCreated_at(new Date(json.getString("created_at"))); status.setFavorited(json.getBoolean("favorited")); status.setId(json.getLong("id")); status.setIn_reply_to_screen_name(json.getString("in_reply_to_screen_name")); status.setIn_reply_to_status_id(json.getString("in_reply_to_status_id")); status.setIn_reply_to_user_id(json.getString("in_reply_to_user_id")); // Log.e("original_pic", json.getString("original_pic")); if (!json.isNull("thumbnail_pic")) { status.setOriginal_pic(json.getString("original_pic")); status.setThumbnail_pic(json.getString("thumbnail_pic")); status.setBmiddle_pic(json.getString("bmiddle_pic")); } status.setSource(json.getString("source")); status.setText(json.getString("text")); // // Log.e("thumbnail_pic", json.getString("thumbnail_pic")); status.setTruncated(json.getBoolean("truncated")); // if (!json.isNull("retweeted_status")) { String retweeted_rlt = json.getString("retweeted_status"); Status retweeted_status = getStatus(retweeted_rlt); status.setRetweetedStatus(retweeted_status); } // status.setUser((User) json.get("user")); String user_rlt = json.getString("user"); if (user_rlt != null && user_rlt != "") { User user = getUser(user_rlt); status.setUser(user); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return status; }
From source file:com.weibo.net.Weibo.java
private List<Status> getMentions(String content) throws WeiboException { List<Status> mentionsList = new ArrayList<Status>(); try {/*from ww w .j av a 2s . co m*/ JSONArray jarray = new JSONArray(content); for (int i = 0; i < jarray.length(); i++) { // Status mention = new Status(); JSONObject json = jarray.getJSONObject(i); mention.setCreated_at((new Date(json.getString("created_at")))); mention.setFavorited(json.getBoolean("favorited")); mention.setId(json.getLong("id")); mention.setIn_reply_to_screen_name(json.getString("in_reply_to_screen_name")); if (!json.isNull("in_reply_to_status_id")) mention.setIn_reply_to_status_id(json.getString("in_reply_to_status_id")); else mention.setIn_reply_to_status_id(null); if (!json.isNull("in_reply_to_user_id")) mention.setIn_reply_to_user_id(json.getString("in_reply_to_user_id")); else mention.setIn_reply_to_user_id(null); mention.setSource(json.getString("source")); // mention.setRetweetedStatus((Status) json.get("retweeted_status")); if (!json.isNull("retweeted_status")) { String retweeted_rlt = json.getString("retweeted_status"); Status retweeted_status = getStatus(retweeted_rlt); mention.setRetweetedStatus(retweeted_status); } mention.setText(json.getString("text")); mention.setTruncated(json.getBoolean("truncated")); // mention.setUser((User) json.get("user")); if (!json.isNull("user")) { String user_rlt = json.getString("user"); User user = getUser(user_rlt); mention.setUser(user); } mentionsList.add(mention); //Add in List<> } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return mentionsList; }
From source file:com.weibo.net.Weibo.java
private List<User> getUserList(String content) throws WeiboException { List<User> users = new ArrayList<User>(); try {/* w w w . j a v a 2 s . c om*/ JSONArray jarry = new JSONArray(content); for (int index = 0; index < jarry.length(); index++) { JSONObject json = jarry.getJSONObject(index); User user = new User(); user.setCity(json.getLong("city")); user.setCreated_at(new Date(json.getString("created_at"))); user.setDescription(json.getString("description")); user.setDomain(json.getString("domain")); user.setFavourites_count(json.getInt("favourites_count")); user.setFollowers_count(json.getInt("followers_count")); user.setFollowing(json.getBoolean("following")); user.setFriends_count(json.getInt("friends_count")); user.setGender(json.getString("gender")); user.setId(json.getLong("id")); user.setLocation(json.getString("location")); user.setName(json.getString("name")); user.setProfile_image_url(json.getString("profile_image_url")); user.setProvince(json.getLong("province")); user.setScreen_name(json.getString("screen_name")); user.setStatuses_count(json.getInt("statuses_count")); user.setUrl(json.getString("url")); user.setVerified(json.getBoolean("verified")); if (!json.isNull("retweeted_status")) { String retweeted_rlt = json.getString("retweeted_status"); Status retweeted_status = getStatus(retweeted_rlt); user.setStatus(retweeted_status); } users.add(user); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return users; }
From source file:com.weibo.net.Weibo.java
private User getUser(String content) throws WeiboException { User user = new User(); try {/* w ww . ja va2s .c o m*/ JSONObject json = new JSONObject(content); user.setCity(json.getLong("city")); user.setCreated_at(parseDate(json.getString("created_at"), "EEE MMM dd HH:mm:ss z yyyy")); user.setId(json.getLong("id")); user.setDescription(json.getString("description")); user.setDomain(json.getString("domain")); user.setFavourites_count(json.getInt("favourites_count")); user.setFollowers_count(json.getInt("followers_count")); user.setFollowing(json.getBoolean("following")); user.setFriends_count(json.getInt("friends_count")); user.setGender(json.getString("gender")); user.setLocation(json.getString("location")); user.setName(json.getString("name")); user.setProfile_image_url(json.getString("profile_image_url")); user.setProvince(json.getLong("province")); user.setScreen_name(json.getString("screen_name")); user.setStatuses_count(json.getInt("statuses_count")); user.setUrl(json.getString("url")); user.setVerified(json.getBoolean("verified")); if (!json.isNull("retweeted_status")) { String retweeted_rlt = json.getString("retweeted_status"); Status retweeted_status = getStatus(retweeted_rlt); user.setStatus(retweeted_status); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return user; }
From source file:com.weibo.net.Weibo.java
/** * POST/* w ww . j av a 2 s . co m*/ * @param cid int64 ID * @param comment URLEncode,140 * @param id ID * @param without_mention @<br> * 0@.0. * */ public Comment postReply(Weibo weibo, Long cid, String comment, Long id, int without_mention) { Comment comments = new Comment(); try { JSONObject json = new JSONObject(reply(weibo, cid, comment, id, without_mention)); comments.setCreated_at(new Date(json.getString("created_at"))); // comments.setFavorited(json.getBoolean("favorited")); comments.setId(json.getLong("id")); // comments.setSource(json.getString("source")); // comments.setStatus((Status) json.get("retweeted_status")); if (!json.isNull("retweeted_status")) { String retweeted_rlt = json.getString("retweeted_status"); Status retweeted_status = getStatus(retweeted_rlt); comments.setStatus(retweeted_status); } comments.setText(json.getString("text")); // comments.setTruncated(json.getBoolean("truncated")); // comments.setUser((User) json.get("user")); if (!json.isNull("user")) { String user_rlt = json.getString("user"); User user = getUser(user_rlt); comments.setUser(user); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (WeiboException e) { // TODO Auto-generated catch block e.printStackTrace(); } return comments; }
From source file:de.fahrgemeinschaft.FahrgemeinschaftConnector.java
@SuppressWarnings("deprecation") private Ride parseRide(JSONObject json) throws JSONException { Ride ride = new Ride().type(Ride.OFFER).mode(Mode.CAR); if (startDate == null) ride.marked(); // myrides ride.who(json.getString(ID_USER));//from ww w.j a va 2 s . c o m String value = json.getString(CONTACTMAIL); if (!value.equals(EMPTY) && !value.equals(NULL)) ride.set(EMAIL, value); value = json.getString(CONTACTMOBILE); if (!value.equals(EMPTY) && !value.equals(NULL)) ride.set(MOBILE, value); value = json.getString(CONTACTLANDLINE); if (!value.equals(EMPTY) && !value.equals(NULL)) ride.set(LANDLINE, value); value = json.getString(PLATE); if (!value.equals(EMPTY) && !value.equals(NULL)) { ride.set(PLATE, value); if (value.equals(BAHN)) ride.mode(Mode.TRAIN); } ride.getDetails().put(PRIVACY, json.getJSONObject(PRIVACY)); ride.set(COMMENT, json.getString(DESCRIPTION)); if (json.getInt(RELEVANCE) == 10) { ride.activate(); } else { ride.deactivate(); } ride.ref(json.getString(TRIP_ID)); ride.seats(json.getInt(PLACES)); if (!json.isNull(PRICE)) { ride.price((int) Double.parseDouble(json.getString(PRICE)) * 100); } else { ride.price(-1); } JSONObject reoccur = json.getJSONObject(REOCCUR); boolean isReoccuring = isReoccuring(reoccur); boolean isMyride = startDate == null; String time = parseTime(json); if (isReoccuring) { ride.getDetails().put(REOCCUR, reoccur); } if (isReoccuring && isMyride) { ride.type(TYPE_OFFER_REOCCURING); } if (isMyride) { if (time.equals(EMPTY)) { Date date = parseDate(json.getString(STARTDATE) + NOTIME); date.setSeconds(59); ride.dep(date); } else { ride.dep(parseDate(json.getString(STARTDATE) + time)); } } else { if (time.equals(EMPTY)) { Date date = parseDate(startDate + NOTIME); date.setSeconds(59); ride.dep(date); } else { ride.dep(parseDate(startDate + time)); } } JSONArray routings = json.getJSONArray(ROUTINGS); ride.from(store(parsePlace(routings.getJSONObject(0).getJSONObject(ORIGIN)))); for (int j = 1; j < routings.length(); j++) { ride.via(store(parsePlace(routings.getJSONObject(j).getJSONObject(DESTINATION)))); } ride.to(store(parsePlace(routings.getJSONObject(0).getJSONObject(DESTINATION)))); return ride; }
From source file:de.fahrgemeinschaft.FahrgemeinschaftConnector.java
private String parseTime(JSONObject json) throws JSONException { // new Date(Long.parseLong(ride.getString("Enterdate")); String time = EMPTY;/*from w w w .ja va 2 s . com*/ if (!json.isNull(STARTTIME)) { time = json.getString(STARTTIME); if (time.length() == 3) time = ZERO + time; if (time.length() != 4) time = EMPTY; } return time; }