List of usage examples for org.json JSONArray optString
public String optString(int index)
From source file:com.example.protocol.STATUSES.java
public void fromJson(JSONObject jsonObject) throws JSONException { if (null == jsonObject) { return;// w ww . ja v a 2 s. c om } JSONArray subItemArray; this.comments_count = jsonObject.optInt("comments_count"); this.text = jsonObject.optString("text"); this.in_reply_to_screen_name = jsonObject.optString("in_reply_to_screen_name"); this.truncated = jsonObject.optBoolean("truncated"); this.bmiddle_pic = jsonObject.optString("bmiddle_pic"); this.thumbnail_pic = jsonObject.optString("thumbnail_pic"); this.source = jsonObject.optString("source"); this.favorited = jsonObject.optBoolean("favorited"); this.original_pic = jsonObject.optString("original_pic"); this.in_reply_to_status_id = jsonObject.optString("in_reply_to_status_id"); this.reposts_count = jsonObject.optInt("reposts_count"); this.created_at = jsonObject.optString("created_at"); this.in_reply_to_user_id = jsonObject.optString("in_reply_to_user_id"); subItemArray = jsonObject.optJSONArray("annotations"); if (null != subItemArray) { for (int i = 0; i < subItemArray.length(); i++) { String subItemObject = subItemArray.optString(i); String subItem = subItemObject; this.annotations.add(subItem); } } this.mid = jsonObject.optString("mid"); USER user = new USER(); user.fromJson(jsonObject.optJSONObject("user")); this.user = user; return; }
From source file:com.footprint.cordova.plugin.localnotification.LocalNotification.java
@Override public boolean execute(String action, final JSONArray args, final CallbackContext command) throws JSONException { if (action.equalsIgnoreCase("add")) { cordova.getThreadPool().execute(new Runnable() { public void run() { JSONObject arguments = args.optJSONObject(0); Options options = new Options(context).parse(arguments); persist(options.getId(), args); add(options, true);// w w w . ja va 2 s . c om } }); } if (action.equalsIgnoreCase("cancel")) { cordova.getThreadPool().execute(new Runnable() { public void run() { String id = args.optString(0); cancel(id); unpersist(id); command.success(); } }); } if (action.equalsIgnoreCase("cancelAll")) { cordova.getThreadPool().execute(new Runnable() { public void run() { cancelAll(); unpersistAll(); command.success(); } }); } if (action.equalsIgnoreCase("isScheduled")) { String id = args.optString(0); isScheduled(id, command); } if (action.equalsIgnoreCase("getScheduledIds")) { getScheduledIds(command); } if (action.equalsIgnoreCase("deviceready")) { cordova.getThreadPool().execute(new Runnable() { public void run() { deviceready(); } }); } if (action.equalsIgnoreCase("pause")) { isInBackground = true; } if (action.equalsIgnoreCase("resume")) { isInBackground = false; } return true; }
From source file:com.hichinaschool.flashcards.libanki.Media.java
/** * Remove provided deletions and all locally-logged deletions, as server has acked them * /*from w w w.java2 s. c om*/ * @param fnames The list of filenames to be deleted. */ public void syncRemove(JSONArray fnames) { mMediaDb.getDatabase().beginTransaction(); try { for (int i = 0; i < fnames.length(); ++i) { String f = fnames.optString(i); if (f == "") { continue; } File file = new File(getDir(), f); if (file.exists()) { file.delete(); } mMediaDb.execute("delete from log where fname = ?", new String[] { f }); mMediaDb.execute("delete from media where fname = ?", new String[] { f }); } mMediaDb.execute("delete from log where type = ?", new String[] { Integer.toString(MEDIA_REM) }); mMediaDb.getDatabase().setTransactionSuccessful(); } finally { mMediaDb.getDatabase().endTransaction(); } }
From source file:io.s4.client.GenericJsonClientStub.java
@Override public EventWrapper eventWrapperFromBytes(byte[] v) { try {/*w w w .ja v a 2s .co m*/ // interpret v as a JSON string String s = new String(v, Charset.forName("UTF8")); JSONObject json = new JSONObject(s); String streamName = json.getString("stream"); String className = json.getString("class"); Class<?> clazz; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { throw new ObjectBuilder.Exception("bad class name for json-encoded object: " + className, e); } String[] keyNames = null; JSONArray keyArray = json.optJSONArray("keys"); if (keyArray != null) { keyNames = new String[keyArray.length()]; for (int i = 0; i < keyNames.length; ++i) { keyNames[i] = keyArray.optString(i); } } String jevent = json.getString("object"); Object obj = GsonUtil.get().fromJson(jevent, clazz); return new EventWrapper(streamName, keyNames, obj); } catch (JSONException e) { logger.error("problem with event JSON", e); } catch (ObjectBuilder.Exception e) { logger.error("failed to build object from JSON", e); } return null; }
From source file:org.changhong.Note.java
public Note(JSONObject json) { // These methods return an empty string if the key is not found setTitle(XmlUtils.unescape(json.optString("title"))); setGuid(json.optString("guid")); setLastChangeDate(json.optString("last-change-date")); String newXMLContent = json.optString("note-content"); setXmlContent(newXMLContent);// w w w. j a v a 2 s . c o m JSONArray jtags = json.optJSONArray("tags"); String tag; tags = new String(); if (jtags != null) { for (int i = 0; i < jtags.length(); i++) { tag = jtags.optString(i); tags += tag + ","; } } }
From source file:com.melniqw.instagramsdk.Media.java
public static Media fromJSON(JSONObject o) throws JSONException { if (o == null) return null; Media media = new Media(); media.id = o.optString("id"); media.type = o.optString("type"); media.createdTime = o.optString("created_time"); media.attribution = o.optString("attribution"); media.image = Image.fromJSON(o.optJSONObject("images")); if (media.type.equals("video")) media.video = Video.fromJSON(o.optJSONObject("videos")); media.link = o.optString("link"); media.filter = o.optString("filter"); media.userHasLiked = o.optBoolean("user_has_liked"); media.user = User.fromJSON(o.optJSONObject("user")); JSONArray tagsJSONArray = o.optJSONArray("tags"); ArrayList<String> tags = new ArrayList<>(); for (int j = 0; j < tagsJSONArray.length(); j++) { tags.add(tagsJSONArray.optString(j)); }/*from w w w . j a va 2 s . co m*/ media.tags.addAll(tags); JSONArray likesJSONArray = o.optJSONObject("likes").optJSONArray("data"); ArrayList<Like> likes = new ArrayList<>(); for (int j = 0; j < likesJSONArray.length(); j++) { JSONObject likeJSON = (JSONObject) likesJSONArray.get(j); likes.add(Like.fromJSON(likeJSON)); } media.likes.addAll(likes); JSONArray commentJSONArray = o.optJSONObject("comments").optJSONArray("data"); ArrayList<Comment> comments = new ArrayList<>(); for (int j = 0; j < commentJSONArray.length(); j++) { JSONObject commentJSON = (JSONObject) commentJSONArray.get(j); comments.add(Comment.fromJSON(commentJSON)); } media.comments.addAll(comments); JSONArray usersInPhotoJSON = o.optJSONArray("users_in_photo"); ArrayList<UserInPhoto> usersInPhotos = new ArrayList<>(); for (int j = 0; j < usersInPhotoJSON.length(); j++) { JSONObject userInPhotoJSON = (JSONObject) usersInPhotoJSON.get(j); usersInPhotos.add(UserInPhoto.fromJSON(userInPhotoJSON)); } media.usersInPhoto.addAll(usersInPhotos); JSONObject locationJSON = o.optJSONObject("location"); if (locationJSON != null) { media.location = Location.fromJSON(locationJSON); } JSONObject captionJSON = o.optJSONObject("caption"); if (captionJSON != null) { media.caption = Comment.fromJSON(captionJSON); } return media; }
From source file:com.example.administrator.datarequest.ningworld.HttpHeaders.java
@Override public void setJSONString(String jsonString) throws JSONException { mSource.clear();//from ww w .j av a 2 s .com JSONObject jsonObject = new JSONObject(jsonString); Iterator<String> keySet = jsonObject.keys(); while (keySet.hasNext()) { String key = keySet.next(); String value = jsonObject.optString(key); JSONArray values = new JSONArray(value); if (values != null) for (int i = 0; i < values.length(); i++) add(key, values.optString(i)); } }
From source file:org.catnut.plugin.zhihu.Zhihu.java
@Override public ContentValues convert(JSONArray array) { long now = System.currentTimeMillis(); ContentValues item = new ContentValues(); // ??item???/*from w ww . j a v a 2 s .c o m*/ item.put(BaseColumns._ID, now); // item.put(STATUS, array.optString(1)); item.put(ANSWER, array.optString(2)); item.put(LAST_ALTER_DATE, array.optLong(4) * 1000); item.put(ANSWER_ID, array.optLong(5)); // JSONArray user = array.optJSONArray(6); if (user != null) { item.put(NICK, user.optString(0)); item.put(UID, user.optString(1)); item.put(AVATAR, user.optInt(2)); } // JSONArray question = array.optJSONArray(7); if (question != null) { item.put(TITLE, question.optString(1, null)); item.put(DESCRIPTION, question.optString(2)); item.put(QUESTION_ID, question.optLong(3)); } return item; }
From source file:census.couchdroid.CouchSession.java
/** * Retrieves a list of all database names from the server * @return/* www .jav a 2s . co m*/ */ public List<String> getDatabaseNames() { CouchResponse resp = get("_all_dbs"); JSONArray ar = resp.getBodyAsJSONArray(); List<String> dbs = new ArrayList<String>(ar.length()); for (int i = 0; i < ar.length(); i++) { dbs.add(ar.optString(i)); } return dbs; }
From source file:com.commontime.plugin.notification.Notification.java
/** * Options from local notification./* w ww . j a v a2 s .c o m*/ * * @param ids Set of local notification IDs * @param command The callback context used when calling back into JavaScript. */ private void getSingle(JSONArray ids, CallbackContext command) { getOptions(ids.optString(0), NotificationWrapper.Type.ALL, command); }