List of usage examples for org.json JSONObject optInt
public int optInt(String key)
From source file:com.vk.sdkweb.api.model.VKApiAudio.java
/** * Fills an Audio instance from JSONObject. *//*from ww w. ja va 2 s . c om*/ public VKApiAudio parse(JSONObject from) { id = from.optInt("id"); owner_id = from.optInt("owner_id"); artist = from.optString("artist"); title = from.optString("title"); duration = from.optInt("duration"); url = from.optString("url"); lyrics_id = from.optInt("lyrics_id"); album_id = from.optInt("album_id"); genre = from.optInt("genre_id"); access_key = from.optString("access_key"); return this; }
From source file:com.vk.sdkweb.api.model.VKApiWikiPage.java
/** * Fills a WikiPage instance from JSONObject. *//*from w ww .j ava2 s . co m*/ public VKApiWikiPage parse(JSONObject source) { id = source.optInt("id"); group_id = source.optInt("group_id"); creator_id = source.optInt("creator_id"); title = source.optString("title"); this.source = source.optString("source"); current_user_can_edit = ParseUtils.parseBoolean(source, "current_user_can_edit"); current_user_can_edit_access = ParseUtils.parseBoolean(source, "current_user_can_edit_access"); who_can_view = source.optInt("who_can_view"); who_can_edit = source.optInt("who_can_edit"); editor_id = source.optInt("editor_id"); edited = source.optLong("edited"); created = source.optLong("created"); parent = source.optString("parent"); parent2 = source.optString("parent2"); return this; }
From source file:com.github.mhendred.face4j.model.Group.java
public Group(final JSONObject jObj) throws JSONException { this.gid = jObj.optInt("gid"); this.uid = jObj.optString("uid"); this.tids = new LinkedList<String>(); final JSONArray jArr = jObj.getJSONArray("tids"); for (int i = 0; i < jArr.length(); i++) { tids.add(jArr.getString(i));/*from www . j a va 2 s . c o m*/ } }
From source file:com.vk.sdkweb.api.model.VKApiMessage.java
/** * Fills a Message instance from JSONObject. */// w w w. ja v a2 s . c o m public VKApiMessage parse(JSONObject source) throws JSONException { id = source.optInt("id"); user_id = source.optInt("user_id"); date = source.optLong("date"); read_state = ParseUtils.parseBoolean(source, "read_state"); out = ParseUtils.parseBoolean(source, "out"); title = source.optString("title"); body = source.optString("body"); attachments.fill(source.optJSONArray("attachments")); fwd_messages = new VKList<VKApiMessage>(source.optJSONArray("fwd_messages"), VKApiMessage.class); emoji = ParseUtils.parseBoolean(source, "emoji"); deleted = ParseUtils.parseBoolean(source, "deleted"); return this; }
From source file:info.axbase.app.VersionInfo.java
public static VersionInfo parse(String text) throws JSONException { JSONTokener jsonParser = new JSONTokener(text); JSONObject msg = (JSONObject) jsonParser.nextValue(); if (msg == null) { return null; }/*from w ww . j a v a2 s . c o m*/ if (msg.optInt("error") == 0) { JSONObject data = msg.optJSONObject("data"); if (data == null) { return null; } VersionInfo versionInfo = new VersionInfo(); versionInfo.fileName = data.optString("fileName"); versionInfo.whatsNew = data.optString("whatsNew"); versionInfo.fileTime = data.optLong("fileTime"); versionInfo.fileSize = data.optLong("fileSize"); versionInfo.appProject = data.optString("appProject"); versionInfo.digest = data.optString("digest"); versionInfo.version = data.optString("version"); return versionInfo; } else { Log.e("ParseError", msg.optString("msg")); return null; } }
From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.PresenceObj.java
public void handleDirectMessage(Context context, Contact from, JSONObject obj) { int presence = obj.optInt(PRESENCE); String id = Long.toString(from.id); long time = obj.optLong(DbObject.TIMESTAMP); ContentValues values = new ContentValues(); values.put(Contact.PRESENCE, presence); values.put(Contact.LAST_PRESENCE_TIME, time); context.getContentResolver().update(Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts"), values, "_id=?", new String[] { id }); }
From source file:plugin.google.iap.v3.util.Purchase.java
public Purchase(String itemType, String jsonPurchaseInfo, String signature) throws JSONException { mItemType = itemType;//from w ww . j ava2 s . c o m mOriginalJson = jsonPurchaseInfo; JSONObject o = new JSONObject(mOriginalJson); mOrderId = o.optString("orderId"); mPackageName = o.optString("packageName"); mSku = o.optString("productId"); mPurchaseTime = o.optLong("purchaseTime"); mDeveloperPayload = o.optString("developerPayload"); mToken = o.optString("token", o.optString("purchaseToken")); mSignature = signature; int state = o.optInt("purchaseState"); switch (state) { case 0: mPurchaseState = State.Purchased; break; case 1: mPurchaseState = State.Cancelled; break; case 2: mPurchaseState = State.Refunded; break; default: mPurchaseState = State.Unknown; } }
From source file:com.basetechnology.s0.agentserver.field.TextField.java
public static Field fromJson(SymbolTable symbolTable, JSONObject fieldJson) { String type = fieldJson.optString("type"); if (type == null || !type.equals("string")) return null; String name = fieldJson.has("name") ? fieldJson.optString("name") : null; String label = fieldJson.has("label") ? fieldJson.optString("label") : null; String description = fieldJson.has("description") ? fieldJson.optString("description") : null; String defaultValue = fieldJson.has("default_value") ? fieldJson.optString("default_value") : null; int minLength = fieldJson.has("min_length") ? fieldJson.optInt("min_length") : 0; int maxLength = fieldJson.has("max_length") ? fieldJson.optInt("max_length") : 0; int nominalWidth = fieldJson.has("nominal_width") ? fieldJson.optInt("nominal_width") : 0; int nominalHeight = fieldJson.has("nominal_height") ? fieldJson.optInt("nominal_height") : 0; String compute = fieldJson.has("compute") ? fieldJson.optString("compute") : null; return new TextField(symbolTable, name, label, description, defaultValue, minLength, maxLength, nominalWidth, nominalHeight, compute); }
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 w w w.j av a 2 s.c o m 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:com.funzio.pure2D.particles.nova.vo.NovaVO.java
public NovaVO(final JSONObject json) throws JSONException { mSource = json;/*from w w w.j a v a2 s.c om*/ version = json.optInt("version"); name = json.optString("name"); pool_size = json.optInt("pool_size"); emitters = getEmitters(json.optJSONArray("emitters")); animators = getAnimators(json.optJSONArray("animators")); motion_trails = getMotionTrails(json.optJSONArray("motion_trails")); // make the maps if (emitters != null) { mEmitterMap = new HashMap<String, NovaEmitterVO>(); for (final NovaEmitterVO vo : emitters) { mEmitterMap.put(vo.name, vo); } } if (animators != null) { mAnimatorMap = new HashMap<String, AnimatorVO>(); for (final AnimatorVO vo : animators) { if (vo != null) { mAnimatorMap.put(vo.name, vo); } } } if (motion_trails != null) { mMotionTrailMap = new HashMap<String, MotionTrailVO>(); for (final MotionTrailVO vo : motion_trails) { if (vo != null) { mMotionTrailMap.put(vo.name, vo); } } } }