List of usage examples for org.json JSONObject optString
public String optString(String key)
From source file:com.norman0406.slimgress.API.Interface.GameBasket.java
public GameBasket(JSONObject json) throws JSONException { mPlayerEntity = null;/*from w w w . ja v a2s . c o m*/ mGameEntities = new LinkedList<GameEntityBase>(); mInventory = new LinkedList<ItemBase>(); mDeletedEntityGuids = new LinkedList<String>(); mEnergyGlobGuids = new LinkedList<XMParticle>(); mPlayerDamages = new LinkedList<PlayerDamage>(); mAPGains = new LinkedList<APGain>(); processPlayerDamages(json.optJSONArray("playerDamages")); processPlayerEntity(json.optJSONArray("playerEntity")); processGameEntities(json.getJSONArray("gameEntities")); processAPGains(json.optJSONArray("apGains")); processLevelUp(json.optJSONObject("levelUp")); processInventory(json.getJSONArray("inventory")); processDeletedEntityGuids(json.getJSONArray("deletedEntityGuids")); processEnergyGlobGuids(json.optJSONArray("energyGlobGuids"), json.optString("energyGlobTimestamp")); }
From source file:com.example.main.BandWViewPagerActivity.java
private void getmArrays(String decode) { // TODO Auto-generated method stub try {//from w w w. j a v a2 s.c o m GlobalID globalID = (GlobalID) getApplication(); JSONArray jsonArray = new JSONArray(decode); if (jsonArray.length() == 0) { return; } else { for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); BandWEntity entity = new BandWEntity(Boolean.valueOf(jsonObject.optString("list_type")), jsonObject.optString("Id"), jsonObject.optString("Title"), jsonObject.optString("Typeid"), Html.fromHtml(jsonObject.optString("Detail")).toString(), jsonObject.optString("Pic"), jsonObject.optString("Time")); if (!entity.getList_type()) { String pic = entity.getPicName(); if (log) Log.v(i + " pic: ", pic); Bitmap bit = FuntionUtil .downloadPic("http://" + globalID.getDBurl() + "/admin/images/" + pic); if (bit != null) { entity.setPic(bit); } else { Bitmap good = BitmapFactory.decodeResource(getResources(), R.drawable.weather_preview); entity.setPic(good); } } // mArrays.add(entity); Message msg = new Message(); msg.what = 1; msg.obj = entity; add_handler.sendMessage(msg); } } } catch (JSONException e) { e.printStackTrace(); return; } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitBranchTest.java
@Test public void testCreateTrackingBranch() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); IPath[] clonePaths = createTestProjects(workspaceLocation); for (IPath clonePath : clonePaths) { // clone a repo JSONObject clone = clone(clonePath); String cloneLocation = clone.getString(ProtocolConstants.KEY_LOCATION); String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION); String branchesLocation = clone.getString(GitConstants.KEY_BRANCH); // overwrite user settings, do not rebase when pulling, see bug 372489 StoredConfig cfg = getRepositoryForContentLocation(cloneContentLocation).getConfig(); cfg.setBoolean(ConfigConstants.CONFIG_BRANCH_SECTION, Constants.MASTER, ConfigConstants.CONFIG_KEY_REBASE, false); cfg.save();//from w w w . j av a 2 s .com // get project/folder metadata WebRequest request = getGetRequest(cloneContentLocation); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); JSONObject project = new JSONObject(response.getText()); JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT); String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD); String gitRemoteUri = gitSection.optString(GitConstants.KEY_REMOTE); // create local branch tracking origin/master final String BRANCH_NAME = "a"; final String REMOTE_BRANCH = Constants.DEFAULT_REMOTE_NAME + "/" + Constants.MASTER; branch(branchesLocation, BRANCH_NAME, REMOTE_BRANCH); // modify, add, commit JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "some change"); addFile(testTxt); request = GitCommitTest.getPostGitCommitRequest(gitHeadUri, "commit1", false); response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // push ServerStatus pushStatus = push(gitRemoteUri, 1, 0, Constants.MASTER, Constants.HEAD, false); assertEquals(true, pushStatus.isOK()); // TODO: replace with RESTful API for git pull when available // try to pull - up to date status is expected Git git = new Git(getRepositoryForContentLocation(cloneContentLocation)); PullResult pullResults = git.pull().call(); assertEquals(Constants.DEFAULT_REMOTE_NAME, pullResults.getFetchedFrom()); assertEquals(MergeStatus.ALREADY_UP_TO_DATE, pullResults.getMergeResult().getMergeStatus()); assertNull(pullResults.getRebaseResult()); // checkout branch which was created a moment ago response = checkoutBranch(cloneLocation, BRANCH_NAME); assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode()); // TODO: replace with RESTful API for git pull when available // try to pull again - now fast forward update is expected pullResults = git.pull().call(); assertEquals(Constants.DEFAULT_REMOTE_NAME, pullResults.getFetchedFrom()); assertEquals(MergeStatus.FAST_FORWARD, pullResults.getMergeResult().getMergeStatus()); assertNull(pullResults.getRebaseResult()); } }
From source file:org.zywx.wbpalmstar.engine.EBounceView.java
public void setBounceParms(int type, JSONObject json, String guestId) { String imagePath = null;//from w w w.j a va 2 s. com String textColor = null; String levelText = null; String pullToReloadText = null; String releaseToReloadText = null; String loadingText = null; String loadingImagePath = null; imagePath = json.optString("imagePath"); if (null != imagePath) { imagePath = BUtility.makeRealPath(imagePath, mBrwView.getCurrentWidget().m_widgetPath, mBrwView.getCurrentWidget().m_wgtType); } textColor = json.optString("textColor"); levelText = json.optString("levelText"); pullToReloadText = json.optString("pullToReloadText"); releaseToReloadText = json.optString("releaseToReloadText"); loadingText = json.optString("loadingText"); if (null != guestId && guestId.equals("donghang")) { loadingImagePath = json.optString("loadingImagePath"); if (null != loadingImagePath) { loadingImagePath = BUtility.makeRealPath(loadingImagePath, mBrwView.getCurrentWidget().m_widgetPath, mBrwView.getCurrentWidget().m_wgtType); } } switch (type) { case EViewEntry.F_BOUNCE_TYPE_TOP: if (null != imagePath && 0 != imagePath.trim().length()) { mHeaderView.setArrowhead(imagePath); } if (null != loadingImagePath && 0 != loadingImagePath.trim().length()) { mHeaderView.setLoadingPic(loadingImagePath); } if ((null == textColor || 0 == textColor.trim().length()) && (null == pullToReloadText || 0 == pullToReloadText.trim().length()) && (null == releaseToReloadText || 0 == releaseToReloadText.trim().length()) && (null == loadingText || 0 == loadingText.trim().length())) { mHeaderView.setContentEmpty(true); } else { if (null != textColor && 0 != textColor.trim().length()) { int color = mBrwView.parseColor(textColor); mHeaderView.setTextColor(color); } if (null != levelText && 0 != levelText.trim().length()) { mHeaderView.setLevelText(levelText); } if (null != releaseToReloadText && 0 != releaseToReloadText.trim().length()) { mHeaderView.setReleaseToReloadText(releaseToReloadText); } if (null != loadingText && 0 != loadingText.trim().length()) { mHeaderView.setLoadingText(loadingText); } if (null != pullToReloadText && 0 != pullToReloadText.trim().length()) { mHeaderView.setPullToReloadText(pullToReloadText); } } break; case EViewEntry.F_BOUNCE_TYPE_BOTTOM: if (null != imagePath && 0 != imagePath.trim().length()) { mTailView.setArrowhead(imagePath); } if (null != loadingImagePath && 0 != loadingImagePath.trim().length()) { mTailView.setLoadingPic(loadingImagePath); } if ((null == textColor || 0 == textColor.trim().length()) && (null == pullToReloadText || 0 == pullToReloadText.trim().length()) && (null == releaseToReloadText || 0 == releaseToReloadText.trim().length()) && (null == loadingText || 0 == loadingText.trim().length())) { mTailView.setContentEmpty(true); } else { if (null != textColor && 0 != textColor.trim().length()) { int color = mBrwView.parseColor(textColor); mTailView.setTextColor(color); } if (null != levelText && 0 != levelText.trim().length()) { mTailView.setLevelText(levelText); } if (null != releaseToReloadText && 0 != releaseToReloadText.trim().length()) { mTailView.setReleaseToReloadText(releaseToReloadText); } if (null != loadingText && 0 != loadingText.trim().length()) { mTailView.setLoadingText(loadingText); } if (null != pullToReloadText && 0 != pullToReloadText.trim().length()) { mTailView.setPullToReloadText(pullToReloadText); } } break; } }
From source file:org.uiautomation.ios.server.command.web.DoubleTapHandler.java
public DoubleTapHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception { super(driver, request); JSONObject payload = request.getPayload(); String elementId = payload.optString("element"); Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize(); RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession().getRemoteWebDriver() .createElement(elementId);/* w ww . j a v a 2 s.c om*/ Point tapPoint = element.getLocation(); tapPoint = CoordinateUtils.forcePointOnScreen(tapPoint, screenSize); String js = doubleTapTemplate.replace(":sessionId", request.getSession()) .replace("tapX", Integer.toString(tapPoint.getX())) .replace("tapY", Integer.toString(tapPoint.getY())); setJS(js); }
From source file:facebook.TiFacebookModule.java
public void makeMeRequest(final AccessToken accessToken) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override/*from w ww . j a v a 2 s. co m*/ public void run() { GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() { @Override public void onCompleted(JSONObject user, GraphResponse response) { FacebookRequestError err = response.getError(); KrollDict data = new KrollDict(); if (user != null) { Log.d(TAG, "user is not null"); data.put(TiFacebookModule.PROPERTY_CANCELLED, false); data.put(TiFacebookModule.PROPERTY_SUCCESS, true); data.put(TiFacebookModule.PROPERTY_UID, user.optString("id")); data.put(TiFacebookModule.PROPERTY_DATA, user.toString()); data.put(TiFacebookModule.PROPERTY_CODE, 0); Log.d(TAG, "firing login event from module"); fireEvent(TiFacebookModule.EVENT_LOGIN, data); } if (err != null) { String errorString = TiFacebookModule.handleError(err); Log.e(TAG, "me request callback error"); Log.e(TAG, "error message: " + err.getErrorMessage()); data.put(TiFacebookModule.PROPERTY_ERROR, errorString); fireEvent(TiFacebookModule.EVENT_LOGIN, data); } } }); request.executeAsync(); } }); }
From source file:com.funzio.pure2D.particles.nova.vo.AnimatorVO.java
public AnimatorVO(final JSONObject json) throws JSONException { super(json);/*from w w w.j a v a2 s .c o m*/ name = json.optString("name"); type = json.optString("type"); if (json.has("accumulating")) { accumulating = json.getBoolean("accumulating"); } loop_mode = json.optString("loop_mode"); loop_count = NovaVO.getListInt(json, "loop_count"); start_delay = NovaVO.getListInt(json, "start_delay"); lifespan = NovaVO.getListInt(json, "lifespan"); }
From source file:org.apache.usergrid.chop.webapp.view.chart.layout.IterationsChartLayout.java
private void handlePointClick(JSONObject json) { runResultId = json.optString("id"); int failures = json.optInt("failures"); boolean buttonVisible = !StringUtils.isEmpty(runResultId) && failures > 0; failuresButton.setVisible(buttonVisible); }
From source file:org.apache.usergrid.chop.webapp.view.chart.layout.IterationsChartLayout.java
private String firstMessages(JSONArray arr) { String s = ""; int len = Math.min(5, arr.length()); for (int i = 0; i < len; i++) { JSONObject json = JsonUtil.get(arr, i); s += "* " + StringUtils.abbreviate(json.optString("message"), 200) + "\n" + StringUtils.abbreviate(json.optString("trace"), 500) + "\n\n"; }/*from w ww .j av a 2 s. c o m*/ return s; }
From source file:com.futureplatforms.kirin.extensions.localnotifications.LocalNotificationsBackend.java
protected boolean scheduleSingleNotification(AlarmManager am, JSONObject obj) { PendingIntent pendingIntent = createPendingIntentForSchedule(obj.optString("id")); long time = obj.optLong("timeMillisSince1970", -1); if (time < 0) { return false; }/*from w w w .ja v a 2s . c o m*/ am.set(AlarmManager.RTC_WAKEUP, time, pendingIntent); return true; }