List of usage examples for org.json JSONObject optLong
public long optLong(String key)
From source file:com.purplefrog.glitchclocka.LearningReadout.java
public void handleJSONResponse(JSONObject json) { JSONObject learning_ = json.optJSONObject("learning"); if (learning_ == null) { learningState = new LearningState("nothing", System.currentTimeMillis() / 1000, 0, "", "you're not learnin' nuthin."); updateReadoutFull();//from ww w.ja v a2s . com return; } String skillId = learning_.keys().next().toString(); JSONObject learning = learning_.optJSONObject(skillId); String name = learning.optString("name"); long timeComplete = learning.optLong("time_complete"); int totalTime = learning.optInt("total_time"); String skillIconURL = learning.optString("icon_100"); String description = learning.optString("description"); learningState = new LearningState(name, timeComplete, totalTime, skillIconURL, description); updateReadoutFull(); final String partial = name + " " + timeComplete + " " + totalTime + " " + skillIconURL + " \n" + description; debugText.setText(partial + "\n\n" + json); }
From source file:fr.immotronic.ubikit.pems.enocean.impl.item.data.EEPD201xxDataImpl.java
public static EEPD201xxDataImpl constructDataFromRecord(int EEPType, JSONObject lastKnownData) { if (lastKnownData == null) { return new EEPD201xxDataImpl(EEPType, null, -1, null, Integer.MIN_VALUE, MeasurementUnit.UNKNOWN, null, null);//www .j a v a2 s . c o m } try { SwitchState[] switchStates = new SwitchState[2]; if (lastKnownData.has("switchState")) { switchStates[0] = SwitchState.valueOf(lastKnownData.getString("switchState")); switchStates[1] = SwitchState.UNKNOWN; } else { switchStates[0] = SwitchState.valueOf(lastKnownData.getString("switchState_0")); switchStates[1] = SwitchState.valueOf(lastKnownData.getString("switchState_1")); } int dimmerValue = lastKnownData.getInt("dimmerValue"); int value = lastKnownData.getInt("value"); MeasurementUnit unit = MeasurementUnit.valueOf(lastKnownData.getString("unit")); Date[] switchStateDates = new Date[2]; if (lastKnownData.has("switchDate")) { long switchDate = lastKnownData.optLong("switchDate"); switchStateDates[0] = (switchDate == 0) ? null : new Date(switchDate); switchStateDates[1] = null; } else { long switchDate = lastKnownData.optLong("switchDate_0"); switchStateDates[0] = (switchDate == 0) ? null : new Date(switchDate); switchDate = lastKnownData.optLong("switchDate_1"); switchStateDates[1] = (switchDate == 0) ? null : new Date(switchDate); } long valueDate = lastKnownData.optLong("valueDate"); Mode mode = null; if (lastKnownData.has("mode")) { mode = Mode.valueOf(lastKnownData.getString("mode")); } return new EEPD201xxDataImpl(EEPType, switchStates, dimmerValue, switchStateDates, value, unit, (valueDate == 0) ? null : new Date(valueDate), mode); } catch (JSONException e) { Logger.error(LC.gi(), null, "constructDataFromRecord(): An exception while building a sensorData from a JSONObject SHOULD never happen. Check the code !", e); return new EEPD201xxDataImpl(EEPType, null, -1, null, Integer.MIN_VALUE, MeasurementUnit.UNKNOWN, null, null); } }
From source file:com.vk.sdkweb.api.model.VKApiPlace.java
/** * Fills a Place instance from JSONObject. *///from www .j a v a2s . c om public VKApiPlace parse(JSONObject from) { id = from.optInt("id"); title = from.optString("title"); latitude = from.optDouble("latitude"); longitude = from.optDouble("longitude"); created = from.optLong("created"); checkins = from.optInt("checkins"); updated = from.optLong("updated"); country_id = from.optInt("country"); city_id = from.optInt("city"); address = from.optString("address"); return this; }
From source file:de.robbers.dashclock.stackextension.StackExtension.java
private void parseReputationResponse(String json) { if (json == null) { return;/*from w w w . j a v a2 s .c o m*/ } mExpandedBody = ""; LongSparseArray reputationArray = new LongSparseArray(); try { JSONArray items = new JSONObject(json).getJSONArray("items"); Log.i(TAG, items.toString(2)); for (int i = 0; i < items.length(); i++) { JSONObject reputation = items.getJSONObject(i); long postId = reputation.optLong("post_id"); int reputationChange = reputation.optInt("reputation_change"); int newValue = reputationChange; newValue += (Integer) reputationArray.get(postId, 0); reputationArray.put(postId, newValue); } List<Long> postIds = new ArrayList<Long>(); for (int i = 0; i < items.length(); i++) { JSONObject reputation = items.getJSONObject(i); long postId = reputation.optLong("post_id"); int reputationChange = reputation.optInt("reputation_change"); if (postIds.contains(postId) || reputationChange == 0) { continue; } postIds.add(postId); int reputationValue = (Integer) reputationArray.get(postId); String title = String.valueOf(Html.fromHtml(reputation.optString("title"))); mExpandedBody += buildExpandedBodyPost(reputationValue, title, postIds.size()); } } catch (JSONException e) { Log.i(TAG, json); e.printStackTrace(); } if (TextUtils.isEmpty(mExpandedBody)) { mExpandedBody = getString(R.string.no_recent_reputation_changes); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.DeleteObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject json) { DBHelper dbh = DBHelper.getGlobal(context); try {//w ww. j av a 2 s. com long[] hashes; if (json.has(HASHES)) { JSONArray jsonHashes = json.optJSONArray(HASHES); hashes = new long[jsonHashes.length()]; for (int i = 0; i < jsonHashes.length(); i++) { hashes[i] = jsonHashes.optLong(i); } } else if (json.has(HASH)) { hashes = new long[] { json.optLong(HASH) }; } else { Log.d(TAG, "DeleteObj with no hashes!"); return; } dbh.markOrDeleteObjs(hashes); } finally { dbh.close(); } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.DeleteObj.java
@Override public void afterDbInsertion(Context context, DbObj obj) { Uri feedUri = obj.getContainingFeed().getUri(); DBHelper dbh = DBHelper.getGlobal(context); try {//ww w.j a v a2 s . c o m JSONObject json = obj.getJson(); long[] hashes; if (json.optJSONArray(HASHES) != null) { JSONArray jsonHashes = json.optJSONArray(HASHES); hashes = new long[jsonHashes.length()]; for (int i = 0; i < jsonHashes.length(); i++) { hashes[i] = jsonHashes.optLong(i); } } else if (json.has(HASH)) { hashes = new long[] { json.optLong(HASH) }; } else { Log.d(TAG, "DeleteObj with no hashes!"); return; } Log.d(TAG, "marking or deleting " + hashes.length); dbh.markOrDeleteFeedObjs(feedUri, hashes, (json.has(FORCE) && json.optBoolean(FORCE))); } finally { dbh.close(); } }
From source file:de.luhmer.owncloudnewsreader.reader.owncloud.InsertItemIntoDatabase.java
private static RssItem parseItem(JSONObject e) throws JSONException { Date pubDate = new Date(e.optLong("pubDate") * 1000); String content = e.optString("body"); content = content.replaceAll("<img[^>]*feedsportal.com.*>", ""); content = content.replaceAll("<img[^>]*statisches.auslieferung.commindo-media-ressourcen.de.*>", ""); content = content.replaceAll("<img[^>]*auslieferung.commindo-media-ressourcen.de.*>", ""); content = content.replaceAll("<img[^>]*rss.buysellads.com.*>", ""); String url = e.optString("url"); String guid = e.optString("guid"); String enclosureLink = e.optString("enclosureLink"); String enclosureMime = e.optString("enclosureMime"); if (enclosureLink.trim().equals("") && guid.startsWith("http://gdata.youtube.com/feeds/api/")) { enclosureLink = url;/*from www . java2 s . co m*/ enclosureMime = "youtube"; } RssItem rssItem = new RssItem(); rssItem.setId(e.getLong("id")); rssItem.setFeedId(e.optLong("feedId")); rssItem.setLink(url); rssItem.setTitle(e.optString("title")); rssItem.setGuid(guid); rssItem.setGuidHash(e.optString("guidHash")); rssItem.setBody(content); rssItem.setAuthor(e.optString("author")); rssItem.setLastModified(new Date(e.optLong("lastModified"))); rssItem.setEnclosureLink(enclosureLink); rssItem.setEnclosureMime(enclosureMime); rssItem.setRead(!e.optBoolean("unread")); rssItem.setRead_temp(rssItem.getRead()); rssItem.setStarred(e.optBoolean("starred")); rssItem.setStarred_temp(rssItem.getStarred()); rssItem.setPubDate(pubDate); return rssItem; /* new RssItem(0, e.optString("id"), e.optString("title"), url, content, !e.optBoolean("unread"), null, e.optString("feedId"), null, date, e.optBoolean("starred"), guid, e.optString("guidHash"), e.optString("lastModified"), e.optString("author"), enclosureLink, enclosureMime); */ }
From source file:com.vk.sdkweb.api.model.VKApiNote.java
/** * Fills a Note instance from JSONObject. *///from w w w.j a v a 2s. c om public VKApiNote parse(JSONObject source) { id = source.optInt("id"); user_id = source.optInt("user_id"); title = source.optString("title"); text = source.optString("text"); date = source.optLong("date"); comments = source.optInt("comments"); read_comments = source.optInt("read_comments"); return this; }
From source file:org.uiautomation.ios.context.BaseWebInspector.java
public List<Cookie> getCookies() { List<Cookie> res = new ArrayList<Cookie>(); JSONObject o = sendCommand(Page.getCookies()); JSONArray cookies = o.optJSONArray("cookies"); if (cookies != null) { for (int i = 0; i < cookies.length(); i++) { JSONObject cookie = cookies.optJSONObject(i); String name = cookie.optString("name"); String value = cookie.optString("value"); String domain = cookie.optString("domain"); String path = cookie.optString("path"); Date expiry = new Date(cookie.optLong("expires")); boolean isSecure = cookie.optBoolean("secure"); Cookie c = new Cookie(name, value, domain, path, expiry, isSecure); res.add(c);/*from w ww . j a v a 2 s. co m*/ } return res; } else { // TODO } return null; }
From source file:net.solosky.litefetion.LiteFetion.java
/** * ????// w w w. j ava 2 s.c o m * @param jo * @throws JSONException */ private Notify processNotify(JSONObject jo) throws JSONException { int dataType = jo.getInt("DataType"); JSONObject data = jo.getJSONObject("Data"); Buddy buddy = null; switch (dataType) { case 2: //??? int userId = data.getInt("uid"); buddy = this.getBuddyByUserId(userId); if (buddy != null) { BuddyState beforeState = buddy.getState(); if (data.optLong("mn") != 0) { buddy.setMobile(data.optLong("mn")); } if (data.optString("nn") != null && data.optString("nn").length() > 0) { buddy.setNickName(data.optString("nn")); } buddy.setImpresa(data.optString("i")); if (data.optString("sms") != null && data.optString("sms").length() > 0) { buddy.setSMSPolicy(data.optString("sms")); } buddy.setSid(data.optInt("sid")); buddy.setPresence(data.optInt("pb")); buddy.setCrc(data.optString("crc")); BuddyState currentState = buddy.getState(); logger.debug("BuddyState changed: buddy=" + buddy.getDisplayName() + ", before=" + beforeState + ", current=" + currentState); return new BuddyStateNotify(beforeState, currentState, buddy); } break; case 3: //?? int fromUserId = data.getInt("fromUid"); String message = data.getString("msg"); int msgType = data.getInt("msgType"); buddy = this.getBuddyByUserId(fromUserId); if (msgType == 2 && buddy != null) { //? logger.debug("Buddy Message received: buddy=" + buddy.getDisplayName() + ", text=" + message); return new BuddyMessageNotify(buddy, message, new Date()); } else if (msgType == 3 || msgType == 4) { //TODO ..?????.. } break; case 4: //? int exitCode = data.getInt("ec"); ClientState state = ClientState.LOGOUT; if (exitCode == 900) { state = ClientState.OTHER_LOGIN; } else if (exitCode >= 902 && exitCode <= 905) { state = ClientState.LOGOUT; } else { state = ClientState.LOGOUT; } logger.debug("ClientState changed: clientState=" + state); return new ClientStateNotify(state); case 5: //? buddy = new Buddy(); buddy.setUserId(data.getInt("uid")); buddy.setUri(data.getString("uri")); buddy.setRelation(Relation.STRANGER); this.buddyList.add(buddy); //? String desc = data.getString("desc"); logger.debug("Buddy Application received: buddy=" + buddy + ", desc=" + desc); return new BuddyApplicationNotify(buddy, desc); case 6: //??,???ba=1 if (data.getInt("ba") == 1) { buddy = this.getBuddyByUserId(data.getInt("uid")); if (buddy != null) { Relation relation = Relation.valueOf(data.getInt("rs")); buddy.setRelation(relation); logger.debug("Buddy confirmed application: buddy=" + buddy + ", isAgreed=" + (relation == Relation.DECLINED)); return new ApplicationConfirmedNotify(buddy, relation == Relation.BUDDY); } } } return null; }