List of usage examples for org.json JSONObject getInt
public int getInt(String key) throws JSONException
From source file:com.userhook.model.UHMessageMetaImage.java
public static UHMessageMetaImage fromJSON(JSONObject json) { UHMessageMetaImage image = new UHMessageMetaImage(); try {//w ww . j a v a 2s .co m if (json.has("url")) { image.url = json.getString("url"); } if (json.has("height")) { image.height = json.getInt("height"); } if (json.has("width")) { image.width = json.getInt("width"); } } catch (Exception e) { Log.e(UserHook.TAG, "error parsing message meta image json", e); } return image; }
From source file:com.df.app.carsWaiting.CarsWaitingListActivity.java
/** * /*from w w w. j a va2s . c o m*/ * @param result */ private void fillInData(String result) { try { JSONArray jsonArray = new JSONArray(result); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); CarsWaitingItem item = new CarsWaitingItem(); item.setPlateNumber(jsonObject.getString("plateNumber")); item.setExteriorColor(jsonObject.getString("exteriorColor")); item.setCarType(jsonObject.getString("licenseModel")); item.setDate(jsonObject.getString("createDate")); item.setCarId(jsonObject.getInt("carId")); item.setJsonObject(jsonObject); data.add(item); } } catch (JSONException e) { e.printStackTrace(); } adapter.notifyDataSetChanged(); startNumber = data.size() + 1; if (data.size() == 0) { footerView.setVisibility(View.GONE); } else { footerView.setVisibility(View.VISIBLE); } // for(int i = 0; i < data.size(); i++) // swipeListView.closeAnimate(i); // // 0, ??(? // if(data.size() == 0) { // DeleteFiles.deleteFiles(AppCommon.photoDirectory); // DeleteFiles.deleteFiles(AppCommon.savedDirectory); // } }
From source file:com.grillecube.editor.ModelEditor.java
private void fillConfig(JSONObject json) { this._config = new HashMap<String, Integer>(); String[] keys = JSONObject.getNames(json); for (String key : keys) { try {//from w ww .ja v a2 s . co m this._config.put(key, json.getInt(key)); } catch (Exception e) { Logger.get().log(Level.ERROR, "Config value can only be integer!"); } } }
From source file:it.unicaradio.android.tasks.SendSongRequestAsyncTask.java
/** * {@inheritDoc}/* ww w. j a v a2 s . co m*/ */ @Override protected Response<String> doInBackground(Void... params) { JSONObject request = new JSONObject(); try { request.put("method", "sendEmail"); request.put("params", songRequest.toJSON(context)); } catch (JSONException e) { return new Response<String>(Error.INTERNAL_GENERIC_ERROR); } String requestJSONString = request.toString(); Log.d(TAG, MessageFormat.format("request: {0}", requestJSONString)); byte[] postData = requestJSONString.getBytes(); byte[] httpResult; try { httpResult = NetworkUtils.httpPost(WEB_SERVICE, postData, "application/json"); } catch (ClientProtocolException e1) { return new Response<String>(Error.INTERNAL_GENERIC_ERROR); } catch (IOException e1) { return new Response<String>(Error.INTERNAL_DOWNLOAD_ERROR); } catch (HttpException e1) { return new Response<String>(Error.INTERNAL_GENERIC_ERROR); } if (httpResult == null) { return new Response<String>(Error.INTERNAL_GENERIC_ERROR); } String httpResultString = new String(httpResult); Log.d(TAG, MessageFormat.format("response: {0}", httpResultString)); try { JSONObject response = new JSONObject(httpResultString); int errorCodeInt = response.getInt("errorCode"); Error errorCode = Error.fromInteger(errorCodeInt); if (errorCode == Error.NO_ERROR) { return new Response<String>(httpResultString); } else { return new Response<String>(errorCode); } } catch (JSONException e) { return new Response<String>(Error.INTERNAL_GENERIC_ERROR); } }
From source file:de.dmxcontrol.programmer.EntityProgrammer.java
public static EntityProgrammer Receive(JSONObject o) { EntityProgrammer entity = new EntityProgrammer(); try {/*from w ww. jav a 2s .c o m*/ if (o.getString("Type").equals(NetworkID)) { int number = o.getInt("Number"); String name = o.getString("Name"); entity.setId(number); entity.setName(name.replace(NetworkID + ": ", ""), true); entity.guid = o.getString("GUID"); } } catch (Exception e) { Log.e("UDP Listener: ", e.getMessage()); DMXControlApplication.SaveLog(); } o = null; if (o == null) { entity.runChangeListener(); } return entity; }
From source file:com.abc.driver.MainActivity.java
public JSONObject getHorder(Integer horder_status) { ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); postParameters.add(new BasicNameValuePair(CellSiteConstants.USER_ID, "" + app.getUser().getId())); postParameters.add(new BasicNameValuePair(CellSiteConstants.HORDER_STATUS, "" + horder_status)); postParameters/*from www . jav a2 s .c om*/ .add(new BasicNameValuePair("offset", String.valueOf(mHorderTypes[mCurrRadioIdx].nDisplayNum))); postParameters.add(new BasicNameValuePair("pagecount", String.valueOf(CellSiteConstants.PAGE_COUNT))); JSONObject response = null; try { response = CellSiteHttpClient.executeHttpPost(CellSiteConstants.GET_MY_HORDER_URL, postParameters); int resultCode = response.getInt(CellSiteConstants.RESULT_CODE); if (CellSiteConstants.RESULT_SUC == resultCode) { parseJson(response); } else { Log.d(TAG, "QUERY RESULT FAILED"); } } catch (Exception e) { e.printStackTrace(); } return response; }
From source file:com.abc.driver.MainActivity.java
public JSONObject getFHorder() { ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>(); postParameters.add(new BasicNameValuePair(CellSiteConstants.USER_ID, "" + app.getUser().getId())); postParameters.add(new BasicNameValuePair("offset", String.valueOf(mFHorderTypes.nDisplayNum))); postParameters.add(new BasicNameValuePair("pagecount", String.valueOf(CellSiteConstants.PAGE_COUNT))); JSONObject response = null; try {/*from w w w . j a v a2s . c om*/ response = CellSiteHttpClient.executeHttpPost(CellSiteConstants.GET_NEW_HORDER_URL, postParameters); int resultCode = response.getInt(CellSiteConstants.RESULT_CODE); if (CellSiteConstants.RESULT_SUC == resultCode) { parseFHorderJson(response); } else { Log.d(TAG, "QUERY RESULT FAILED"); } } catch (Exception e) { e.printStackTrace(); } return response; }
From source file:com.github.koraktor.steamcondenser.community.WebApiTest.java
@Test public void testGetJSONData() throws Exception { HashMap<String, Object> params = new HashMap<String, Object>(); params.put("test", "param"); String data = mock(String.class); spy(WebApi.class); doReturn(data).when(WebApi.class, "getJSON", "interface", "method", 2, params); JSONObject json = mock(JSONObject.class); JSONObject result = mock(JSONObject.class); when(json.getJSONObject("result")).thenReturn(result); when(result.getInt("status")).thenReturn(1); whenNew(JSONObject.class).withParameterTypes(String.class).withArguments(data).thenReturn(json); assertThat(WebApi.getJSONData("interface", "method", 2, params), is(result)); }
From source file:com.github.koraktor.steamcondenser.community.WebApiTest.java
@Test public void testGetJSONDataFailed() throws Exception { String data = mock(String.class); spy(WebApi.class); doReturn(data).when(WebApi.class, "getJSON", "interface", "method", 2, null); JSONObject json = mock(JSONObject.class); JSONObject result = mock(JSONObject.class); when(json.getJSONObject("result")).thenReturn(result); when(result.getInt("status")).thenReturn(0); when(result.getString("statusDetail")).thenReturn("Error"); whenNew(JSONObject.class).withParameterTypes(String.class).withArguments(data).thenReturn(json); this.exception.expect(WebApiException.class); this.exception .expectMessage("The Web API request failed with the following error: Error (status code: 0)."); WebApi.getJSONData("interface", "method", 2); }
From source file:face4j.response.LimitsResponseImpl.java
public LimitsResponseImpl(final String json) throws FaceClientException { super(json);/* w w w . ja v a 2 s .c om*/ try { // usage stats final JSONObject usage = response.getJSONObject("usage"); namespaceRemaining = optInt(usage, "namespace_remaining"); namespaceUsed = optInt(usage, "namespace_used"); namespaceLimit = optInt(usage, "namespace_limit"); restTimeString = usage.getString("reset_time_text"); resetDate = new Date(usage.getLong("reset_time")); remaining = usage.getInt("remaining"); used = usage.getInt("used"); limit = usage.getInt("limit"); } catch (JSONException jex) { logger.error("Error: ", jex); throw new FaceClientException(jex); } }