List of usage examples for org.json JSONObject optInt
public int optInt(String key)
From source file:org.chromium.ChromeUsb.java
private static byte[] getByteBufferForTransfer(CordovaArgs args, JSONObject params, int direction) throws JSONException { if (direction == UsbConstants.USB_DIR_OUT) { // OUT transfer requires data positional argument. return args.getArrayBuffer(ARG_INDEX_DATA_ARRAYBUFFER); } else {/*from w w w . ja v a 2 s.c o m*/ // IN transfer requires client to pass the length to receive. return new byte[params.optInt("length")]; } }
From source file:com.vk.sdkweb.api.model.VKApiNote.java
/** * Fills a Note instance from JSONObject. *///w ww . jav a2 s.co m 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:com.galactogolf.serialization.JSONSerializer.java
private static LevelDefinition fromLevelDefinitionJSON(JSONObject levelDefnJSON) throws JSONException { LevelDefinition levelDefn = new LevelDefinition(levelDefnJSON.getString(JSONTags.LEVEL_DEFINITION_NAME)); levelDefn.setDescription(levelDefnJSON.optString(JSONTags.LEVEL_DEFINITION_DESCRIPTION)); levelDefn.setPar(levelDefnJSON.optInt(JSONTags.LEVEL_DEFINITION_PAR)); JSONArray npcsJSON = levelDefnJSON.optJSONArray(JSONTags.LEVEL_DEFINITION_NPCS); if (npcsJSON != null) { for (int i = 0; i < npcsJSON.length(); i++) { levelDefn.GetNPCDefinitions() .add(JSONSerializer.fromEntityDefinitionJSON(npcsJSON.getJSONObject(i))); }/*from w w w . j a v a2s .c o m*/ } levelDefn.setPlayerDefinition(JSONSerializer .fromEntityDefinitionJSON(levelDefnJSON.getJSONObject(JSONTags.LEVEL_DEFINITION_PLAYER))); return levelDefn; }
From source file:org.jjdltc.cordova.plugin.sftp.asyncSFTPAction.java
@SuppressWarnings("static-access") private void doConnection(JSONObject hostData) throws JSchException { this.jsch = new JSch(); this.jsch.setConfig("StrictHostKeyChecking", "no"); this.session = jsch.getSession(hostData.optString("user"), hostData.optString("host"), hostData.optInt("port")); this.session.setPassword(hostData.optString("pswd")); this.session.connect(); this.sftpChannel = (ChannelSftp) session.openChannel("sftp"); this.sftpChannel.connect(); Log.d("SFTP Plugin - JJDLTC", "Connection Open."); this.jsEvent("SFTPActionConnected", null); }
From source file:com.basetechnology.s0.agentserver.field.DateField.java
public static Field fromJson(SymbolTable symbolTable, JSONObject fieldJson) { String type = fieldJson.optString("type"); if (type == null || !type.equals("date")) 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; String minValue = fieldJson.has("min_value") ? fieldJson.optString("min_value") : null; String maxValue = fieldJson.has("max_value") ? fieldJson.optString("max_value") : null; int nominalWidth = fieldJson.has("nominal_width") ? fieldJson.optInt("nominal_width") : 0; String compute = fieldJson.has("compute") ? fieldJson.optString("compute") : null; return new DateField(symbolTable, name, label, description, defaultValue, minValue, maxValue, nominalWidth, compute);/*from w ww . j ava2s .c o m*/ }
From source file:net.solosky.litefetion.LiteFetion.java
/** * ????/*from ww w . ja va 2s . co 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; }
From source file:com.example.protocol.COMMENT.java
public void fromJson(JSONObject jsonObject) throws JSONException { if (null == jsonObject) { return;//from w w w .java 2s . c om } this.id = jsonObject.optInt("id"); this.likes_count = jsonObject.optInt("likes_count"); this.body = jsonObject.optString("body"); this.created_at = jsonObject.optString("created_at"); PLAYER player = new PLAYER(); player.fromJson(jsonObject.optJSONObject("player")); this.player = player; return; }
From source file:com.zotoh.core.util.JSONUte.java
/** * @param obj/* w w w .ja v a2 s . c o m*/ * @param key * @return */ public static int getInt(JSONObject obj, String key) { return obj == null ? 0 : obj.optInt(key); }
From source file:com.rapid.actions.Database.java
public Database(RapidHttpServlet rapidServlet, JSONObject jsonAction) throws Exception { // call the super parameterless constructor which sets the xml version super();/*ww w .ja v a 2 s . com*/ // save all key/values from the json into the properties for (String key : JSONObject.getNames(jsonAction)) { // add all json properties to our properties, except for query if (!"query".equals(key) && !"showLoading".equals(key) && !"childDatabaseActions".equals(key) && !"successActions".equals(key) && !"errorActions".equals(key) && !"childActions".equals(key)) addProperty(key, jsonAction.get(key).toString()); } // try and build the query object JSONObject jsonQuery = jsonAction.optJSONObject("query"); // check we got one if (jsonQuery != null) { // get the parameters ArrayList<Parameter> inputs = getParameters(jsonQuery.optJSONArray("inputs")); ArrayList<Parameter> outputs = getParameters(jsonQuery.optJSONArray("outputs")); String sql = jsonQuery.optString("SQL"); boolean multiRow = jsonQuery.optBoolean("multiRow"); int databaseConnectionIndex = jsonQuery.optInt("databaseConnectionIndex"); // make the object _query = new Query(inputs, outputs, sql, multiRow, databaseConnectionIndex); } // look for showLoading _showLoading = jsonAction.optBoolean("showLoading"); // grab any successActions JSONArray jsonChildDatabaseActions = jsonAction.optJSONArray("childDatabaseActions"); // if we had some if (jsonChildDatabaseActions != null) { // instantiate collection _childDatabaseActions = new ArrayList<Database>(); // loop them for (int i = 0; i < jsonChildDatabaseActions.length(); i++) { // get one JSONObject jsonChildDatabaseAction = jsonChildDatabaseActions.getJSONObject(i); // instantiate and add to collection _childDatabaseActions.add(new Database(rapidServlet, jsonChildDatabaseAction)); } } // grab any successActions JSONArray jsonSuccessActions = jsonAction.optJSONArray("successActions"); // if we had some instantiate our collection if (jsonSuccessActions != null) _successActions = Control.getActions(rapidServlet, jsonSuccessActions); // grab any errorActions JSONArray jsonErrorActions = jsonAction.optJSONArray("errorActions"); // if we had some instantiate our collection if (jsonErrorActions != null) _errorActions = Control.getActions(rapidServlet, jsonErrorActions); }
From source file:com.example.protocol.SHOT.java
public void fromJson(JSONObject jsonObject) throws JSONException { if (null == jsonObject) { return;// w w w. jav a 2s .c om } JSONArray subItemArray; this.id = jsonObject.optInt("id"); this.title = jsonObject.optString("title"); this.url = jsonObject.optString("url"); this.short_url = jsonObject.optString("short_url"); this.image_url = jsonObject.optString("image_url"); this.image_teaser_url = jsonObject.optString("image_teaser_url"); this.width = jsonObject.optInt("width"); this.height = jsonObject.optInt("height"); this.views_count = jsonObject.optInt("views_count"); this.likes_count = jsonObject.optInt("likes_count"); this.comments_count = jsonObject.optInt("comments_count"); this.rebounds_count = jsonObject.optInt("rebounds_count"); this.rebounds_source_id = jsonObject.optInt("rebounds_source_id"); this.created_at = jsonObject.optString("created_at"); this.player = new PLAYER(); this.player.fromJson(jsonObject.optJSONObject("player")); }