List of usage examples for org.json JSONArray getInt
public int getInt(int index) throws JSONException
From source file:com.openerp.addons.note.EditNoteFragment.java
public void updateNote(int row_id) { try {/*from ww w . j ava 2 s. c o m*/ JSONArray tagID = db.getSelectedTagId(selectedTags); long stage_id = Long.parseLong(stages.get(noteStages.getSelectedItem().toString())); ContentValues values = new ContentValues(); JSONObject vals = new JSONObject(); // If Pad Installed Over Server if (padAdded) { JSONArray url = new JSONArray(); url.put(originalMemo); JSONObject obj = oe_obj.call_kw("pad.common", "pad_get_content", url); // HTMLHelper helper = new HTMLHelper(); String link = HTMLHelper.htmlToString(obj.getString("result")); values.put("stage_id", stage_id); vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString())); values.put("name", db.generateName(link)); vals.put("name", values.get("name").toString()); values.put("memo", obj.getString("result")); vals.put("memo", values.get("memo").toString()); values.put("note_pad_url", originalMemo); vals.put("note_pad_url", values.get("note_pad_url").toString()); } // If Pad Not Installed Over Server else { values.put("stage_id", stage_id); vals.put("stage_id", Integer.parseInt(values.get("stage_id").toString())); values.put("name", db.generateName(noteMemo.getText().toString())); vals.put("name", values.get("name").toString()); values.put("memo", Html.toHtml(noteMemo.getText())); vals.put("memo", values.get("memo").toString()); } JSONArray tag_ids = new JSONArray(); tag_ids.put(6); tag_ids.put(false); JSONArray c_ids = new JSONArray(tagID.toString()); tag_ids.put(c_ids); vals.put("tag_ids", new JSONArray("[" + tag_ids.toString() + "]")); // This will update Notes over Server And Local database db = new NoteDBHelper(scope.context()); if (oe_obj.updateValues(db.getModelName(), vals, row_id)) { db.write(db, values, row_id, true); db.executeSQL("delete from note_note_note_tag_rel where note_note_id = ? and oea_name = ?", new String[] { row_id + "", scope.User().getAndroidName() }); for (int i = 0; i < tagID.length(); i++) { ContentValues rel_vals = new ContentValues(); rel_vals.put("note_note_id", row_id); rel_vals.put("note_tag_id", tagID.getInt(i)); rel_vals.put("oea_name", scope.User().getAndroidName()); SQLiteDatabase insertDb = db.getWritableDatabase(); insertDb.insert("note_note_note_tag_rel", null, rel_vals); insertDb.close(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.hunch.api.HunchQuestion.java
static HunchQuestion buildFromJSON(JSONObject json) { final HunchQuestion.Builder builder = getBuilder(); final HunchResponse.Builder respBuilder = HunchResponse.getBuilder(); // build the HunchQuestion object int id = Integer.MIN_VALUE, topicId = Integer.MIN_VALUE; String text = "", imgUrl = ""; JSONArray jsonResIds; List<HunchResponse> responses = new ArrayList<HunchResponse>(); try {//from w w w.j a v a 2s . co m jsonResIds = json.getJSONArray("responseIds"); } catch (JSONException e) { throw new RuntimeException("Couldn't build HunchQuestion!", e); } for (int i = 0; i < jsonResIds.length(); i++) { JSONObject obj = new JSONObject(); try { obj.put("responseIds", jsonResIds); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } respBuilder.init(obj); try { respBuilder.setId(jsonResIds.getInt(i)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } responses.add(respBuilder.buildForQuestion()); } try { String tId = json.getString("topicId"); try { topicId = Integer.parseInt(tId); } catch (NumberFormatException e) { if (tId.equals("THAY")) { // Teach Hunch About You! topicId = THAY_TOPIC_ID; } else { // some other cause of the NFE throw new RuntimeException("Couldn't build HunchQuestion!", e); } } id = json.getInt("id"); text = json.getString("text"); imgUrl = json.getString("imageUrl"); } catch (NumberFormatException e) { throw new RuntimeException("Couldn't build HunchQuestion!", e); } catch (JSONException e) { throw new RuntimeException("Couldn't build HunchQuestion!", e); } finally { builder.init(json).setId(id).setTopicId(topicId).setText(text).setImageUrl(imgUrl) .setResponses(responses); } return builder.build(); }
From source file:com.android.cast.demo.GameMessageStream.java
/** * Processes all JSON messages received from the receiver device and performs the appropriate * action for the message. Recognizable messages are of the form: * //from w ww . j ava2s.c om * <ul> * <li> KEY_JOINED: a player joined the current game * <li> KEY_MOVED: a player made a move * <li> KEY_ENDGAME: the game has ended in one of the END_STATE_* states * <li> KEY_ERROR: a game error has occurred * <li> KEY_BOARD_LAYOUT_RESPONSE: the board has been laid out in some new configuration * </ul> * * <p>No other messages are recognized. */ @Override public void onMessageReceived(JSONObject message) { try { Log.d(TAG, "onMessageReceived: " + message); if (message.has(KEY_EVENT)) { String event = message.getString(KEY_EVENT); if (KEY_JOINED.equals(event)) { Log.d(TAG, "JOINED"); try { String player = message.getString(KEY_PLAYER); String opponentName = message.getString(KEY_OPPONENT); onGameJoined(player, opponentName); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_MOVED.equals(event)) { Log.d(TAG, "MOVED"); try { String player = message.getString(KEY_PLAYER); int row = message.getInt(KEY_ROW); int column = message.getInt(KEY_COLUMN); boolean isGameOver = message.getBoolean(KEY_GAME_OVER); onGameMove(player, row, column, isGameOver); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_ENDGAME.equals(event)) { Log.d(TAG, "ENDGAME"); try { String endState = message.getString(KEY_END_STATE); int winningLocation = -1; if (END_STATE_ABANDONED.equals(endState) == false) { winningLocation = message.getInt(KEY_WINNING_LOCATION); } onGameEnd(endState, winningLocation); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_ERROR.equals(event)) { Log.d(TAG, "ERROR"); try { String errorMessage = message.getString(KEY_MESSAGE); onGameError(errorMessage); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_BOARD_LAYOUT_RESPONSE.equals(event)) { Log.d(TAG, "Board Layout"); int[][] boardLayout = new int[3][3]; try { JSONArray boardJSONArray = message.getJSONArray(KEY_BOARD); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { boardLayout[i][j] = boardJSONArray.getInt(i * 3 + j); } } onGameBoardLayout(boardLayout); } catch (JSONException e) { e.printStackTrace(); } } } else { Log.w(TAG, "Unknown message: " + message); } } catch (JSONException e) { Log.w(TAG, "Message doesn't contain an expected key.", e); } }
From source file:com.liferay.mobile.android.v7.commentmanagerjsonws.CommentmanagerjsonwsService.java
public Integer getCommentsCount(long groupId, String className, long classPK) throws Exception { JSONObject _command = new JSONObject(); try {//www .ja va 2 s.c om JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("className", checkNull(className)); _params.put("classPK", classPK); _command.put("/comment.commentmanagerjsonws/get-comments-count", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getInt(0); }
From source file:com.wholegroup.rally.Rally.java
/** * ?? JSON ?.//from w w w.j ava2 s.com */ public void fromJSON(String strJSON) { try { JSONObject jsonObject = new JSONObject(strJSON); JSONArray jsonArray; JSONArray jsonArray2; jsonArray = jsonObject.getJSONArray("m_arrField"); for (int y = 0; y < jsonArray.length(); y++) { if (FIELDHEIGHT <= y) { break; } jsonArray2 = jsonArray.getJSONArray(y); for (int x = 0; x < jsonArray2.length(); x++) { if (FIELDWIDTH <= x) { break; } m_arrField[y][x] = jsonArray2.getInt(x); } } m_iScore = jsonObject.getInt("m_iScore"); m_iTypeGame = jsonObject.getInt("m_iTypeGame"); m_iPlayerPos = jsonObject.getInt("m_iPlayerPos"); m_iLifeCount = jsonObject.getInt("m_iLifeCount"); m_iDensity = jsonObject.getInt("m_iDensity"); m_iSpeedMS = jsonObject.getInt("m_iSpeedMS"); } catch (JSONException e) { e.printStackTrace(); } }
From source file:com.polyvi.xface.extension.audio.XAudioExt.java
@Override public XExtensionResult exec(String action, JSONArray args, XCallbackContext callbackCtx) throws JSONException { String appId = mWebContext.getApplication().getAppId(); XExtensionResult.Status status = XExtensionResult.Status.NO_RESULT; if (action.equals(COMMAND_PLAY)) { XAudioStatusChangeListener listener = new XAudioStatusChangeListener(callbackCtx); play(args.getString(0), args.getString(1), mWebContext.getWorkSpace(), listener); } else if (action.equals(COMMAND_STOP)) { stop(args.getString(0));// ww w .ja v a 2 s . c o m } else if (action.equals(COMMAND_PAUSE)) { pause(args.getString(0)); } else if (action.equals(COMMAND_SEEKTO)) { seekTo(args.getString(0), args.getInt(1)); } else if (action.equals(COMMAND_RELEASE)) { boolean ret = release(args.getString(0)); return new XExtensionResult(status, ret); } else if (action.equals(COMMAND_GETCURRENTPOSITION)) { int pos = getCurrentPosition(args.getString(0), appId); return new XExtensionResult(XExtensionResult.Status.OK, pos); } else if (action.equals(COMMAND_STARTRECORDING)) { XAudioStatusChangeListener listener = new XAudioStatusChangeListener(callbackCtx); startRecording(args.getString(0), args.getString(1), mWebContext.getWorkSpace(), listener); } else if (action.equals(COMMAND_STOPRECORDING)) { stopRecording(args.getString(0)); } else if (action.equals(COMMAND_SETVOLUME)) { setVolume(args.getString(0), Float.parseFloat(args.getString(1))); } return new XExtensionResult(status); }
From source file:com.grillecube.common.utils.JSONHelper.java
/** json array to float array */ public static int[] jsonArrayToIntArray(JSONArray array) { int[] integers = new int[array.length()]; for (int i = 0; i < integers.length; i++) { integers[i] = array.getInt(i); }//from w w w.j a v a 2s. c o m return (integers); }
From source file:com.liferay.mobile.android.v7.journalarticle.JournalArticleService.java
public Integer searchCount(long companyId, long groupId, JSONArray folderIds, long classNameId, String articleId, double version, String title, String description, String content, JSONArray ddmStructureKeys, JSONArray ddmTemplateKeys, long displayDateGT, long displayDateLT, int status, long reviewDate, boolean andOperator) throws Exception { JSONObject _command = new JSONObject(); try {// w w w. j a va2 s . c o m JSONObject _params = new JSONObject(); _params.put("companyId", companyId); _params.put("groupId", groupId); _params.put("folderIds", checkNull(folderIds)); _params.put("classNameId", classNameId); _params.put("articleId", checkNull(articleId)); _params.put("version", version); _params.put("title", checkNull(title)); _params.put("description", checkNull(description)); _params.put("content", checkNull(content)); _params.put("ddmStructureKeys", checkNull(ddmStructureKeys)); _params.put("ddmTemplateKeys", checkNull(ddmTemplateKeys)); _params.put("displayDateGT", displayDateGT); _params.put("displayDateLT", displayDateLT); _params.put("status", status); _params.put("reviewDate", reviewDate); _params.put("andOperator", andOperator); _command.put("/journal.journalarticle/search-count", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getInt(0); }
From source file:com.liferay.mobile.android.v7.journalarticle.JournalArticleService.java
public Integer searchCount(long companyId, long groupId, JSONArray folderIds, long classNameId, String articleId, double version, String title, String description, String content, String ddmStructureKey, String ddmTemplateKey, long displayDateGT, long displayDateLT, int status, long reviewDate, boolean andOperator) throws Exception { JSONObject _command = new JSONObject(); try {/*from w w w.j ava 2 s . com*/ JSONObject _params = new JSONObject(); _params.put("companyId", companyId); _params.put("groupId", groupId); _params.put("folderIds", checkNull(folderIds)); _params.put("classNameId", classNameId); _params.put("articleId", checkNull(articleId)); _params.put("version", version); _params.put("title", checkNull(title)); _params.put("description", checkNull(description)); _params.put("content", checkNull(content)); _params.put("ddmStructureKey", checkNull(ddmStructureKey)); _params.put("ddmTemplateKey", checkNull(ddmTemplateKey)); _params.put("displayDateGT", displayDateGT); _params.put("displayDateLT", displayDateLT); _params.put("status", status); _params.put("reviewDate", reviewDate); _params.put("andOperator", andOperator); _command.put("/journal.journalarticle/search-count", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getInt(0); }
From source file:com.liferay.mobile.android.v7.journalarticle.JournalArticleService.java
public Integer searchCount(long companyId, long groupId, JSONArray folderIds, long classNameId, String keywords, double version, String ddmStructureKey, String ddmTemplateKey, long displayDateGT, long displayDateLT, int status, long reviewDate) throws Exception { JSONObject _command = new JSONObject(); try {//from w ww . j a v a2 s . c om JSONObject _params = new JSONObject(); _params.put("companyId", companyId); _params.put("groupId", groupId); _params.put("folderIds", checkNull(folderIds)); _params.put("classNameId", classNameId); _params.put("keywords", checkNull(keywords)); _params.put("version", version); _params.put("ddmStructureKey", checkNull(ddmStructureKey)); _params.put("ddmTemplateKey", checkNull(ddmTemplateKey)); _params.put("displayDateGT", displayDateGT); _params.put("displayDateLT", displayDateLT); _params.put("status", status); _params.put("reviewDate", reviewDate); _command.put("/journal.journalarticle/search-count", _params); } catch (JSONException _je) { throw new Exception(_je); } JSONArray _result = session.invoke(_command); if (_result == null) { return null; } return _result.getInt(0); }