List of usage examples for org.json JSONObject toString
public String toString()
From source file:app.hanks.com.conquer.activity.LoginActivity.java
@Override public void onComplete(Object o) { try {/*from w w w.j av a 2 s .co m*/ JSONObject jsonObject = new JSONObject(o.toString()); String userId = jsonObject.getString("openid"); String expiresIn = jsonObject.getString("expires_in"); String accessToken = jsonObject.getString("access_token"); BmobUser.BmobThirdUserAuth authInfo = new BmobUser.BmobThirdUserAuth("qq", accessToken, expiresIn, userId); BmobUser.loginWithAuthData(context, authInfo, new OtherLoginListener() { @Override public void onSuccess(JSONObject userAuth) { L.i("QQ??" + userAuth.toString()); getQQInfo(userAuth); } @Override public void onFailure(int code, String msg) { // TODO Auto-generated method stub Log.i("smile", "" + msg); } }); } catch (JSONException e) { e.printStackTrace(); } }
From source file:org.onepf.store.data.SkuDetails.java
public String toJson() { JSONObject o = new JSONObject(); try {// w ww.j a va 2 s. c o m o.put("productId", _sku); o.put("type", _type); o.put("price", _price); o.put("title", _title); o.put("description", _description); } catch (JSONException e) { Log.e(StoreApplication.TAG, "Couldn't serialize " + getClass().getSimpleName()); return ""; } return o.toString(); }
From source file:com.tesobe.hello_obp.activity.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); privateAccountsJsonView = (TextView) findViewById(R.id.private_accounts_json); // Request the banks available from the API new AsyncTask<Void, Void, String>() { @Override/*w w w.j a v a 2 s .c om*/ /** * @return A String containing the json representing the available banks, or an error message */ protected String doInBackground(Void... params) { try { JSONObject banksJson = OBPRestClient.getBanksJson(); return banksJson.toString(); } catch (ExpiredAccessTokenException e) { // login again / re-authenticate redoOAuth(); return ""; } catch (ObpApiCallFailedException e) { return "Sorry, there was an error!"; } } @Override protected void onPostExecute(String result) { privateAccountsJsonView.setText(result); } }.execute(); }
From source file:net.zionsoft.obadiah.model.notification.PushNotificationRegister.java
@Override protected void onHandleIntent(Intent intent) { GoogleCloudMessaging gcm = null;//w w w .j av a 2s . c o m try { gcm = GoogleCloudMessaging.getInstance(this); final String registrationId = gcm.register(getString(R.string.google_cloud_messaging_sender_id)); final JSONObject jsonObject = new JSONObject(); jsonObject.put("pushNotificationId", registrationId); jsonObject.put("utcOffset", TimeZone.getDefault().getOffset(new Date().getTime()) / 1000); jsonObject.put("locale", Locale.getDefault().toString().toLowerCase()); NetworkHelper.post(NetworkHelper.DEVICE_ACCOUNT_URL, jsonObject.toString()); Analytics.trackNotificationEvent("device_registered", null); } catch (IOException | JSONException e) { Crashlytics.logException(e); } finally { if (gcm != null) { gcm.close(); } } }
From source file:it_minds.dk.eindberetningmobil_android.views.UploadingView.java
private void TrySendReport(final DriveReport toSend) { final Timer timer = new Timer(); ServerFactory.getInstance(this).sendReport(toSend, new ResultCallback<JSONObject>() { @Override//from w w w. j ava 2 s. co m public void onSuccess(JSONObject result) { Log.d("RESULT", result.toString()); updateStatusText(getString(R.string.success)); spinner.setVisibility(View.INVISIBLE); MainSettings.getInstance(UploadingView.this).removeSavedReport(saveableReport); timer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { startActivity(new Intent(UploadingView.this, StartActivity.class)); finish(); } }); } }, WAIT_TIME_MS_SUCCESS_DISSAPEAR); } @Override public void onError(Exception error) { updateStatusText(getString(R.string.error)); Log.e("temp", "error", error); new ConfirmationDialog(UploadingView.this, getString(R.string.error_dialog_title), getString(R.string.send_report_error), getString(R.string.send_report_error_retry), getString(R.string.send_report_error_cancel), null, new ResultCallback<Boolean>() { @Override public void onSuccess(Boolean result) { TrySendReport(toSend); } @Override public void onError(Exception error) { startActivity(new Intent(UploadingView.this, StartActivity.class)); finish(); } }).showDialog(); } }); /* ServerFactory.getInstance(this).sendReport(toSend, new ResultCallback<UserInfo>() { @Override public void onSuccess(UserInfo result) { updateStatusText(getString(R.string.success)); spinner.setVisibility(View.INVISIBLE); MainSettings.getInstance(UploadingView.this).removeSavedReport(saveableReport); timer.schedule(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { startActivity(new Intent(UploadingView.this, StartActivity.class)); finish(); } }); } }, WAIT_TIME_MS_SUCCESS_DISSAPEAR); } @Override public void onError(final Exception error) { updateStatusText(getString(R.string.error)); Log.e("temp", "error", error); new ConfirmationDialog(UploadingView.this, getString(R.string.error_dialog_title), getString(R.string.send_report_error), getString(R.string.send_report_error_retry), getString(R.string.send_report_error_cancel), null, new ResultCallback<Boolean>() { @Override public void onSuccess(Boolean result) { TrySendReport(toSend); } @Override public void onError(Exception error) { startActivity(new Intent(UploadingView.this, StartActivity.class)); finish(); } }).showDialog(); } }); */ }
From source file:com.walletplus.util.SendNotification.java
public void sendNotification(String regId, String apiKey, String title, String desc, String type, String amount, String id, String eid, String url, String vpackage) { try {//from w w w.j a v a 2 s .c o m JSONObject dataObj = new JSONObject(); dataObj.put("type", type); dataObj.put("title", title); dataObj.put("desc", desc); dataObj.put("amount", amount); dataObj.put("sid", id); dataObj.put("eid", eid); dataObj.put("url", url); dataObj.put("package", vpackage); String data = dataObj.toString(); Sender sender = new Sender(apiKey); Message message = new Message.Builder().collapseKey(id).addData("message", data).build(); Result r = sender.send(message, regId, 2); log.info("Error : " + r.getErrorCodeName()); log.info("MSG : " + r.getMessageId()); } catch (Exception ex) { } }
From source file:com.cubusmail.user.UserAccountDao.java
/** * @param account/*from w ww .jav a 2 s.c o m*/ * @return */ public Long saveUserAccount(UserAccount account) { JSONObject jsonObject = new JSONObject(account.getPreferences()); account.setPreferencesJson(jsonObject.toString()); prepareAccount(account); getHibernateTemplate().saveOrUpdate(account); if (logger.isDebugEnabled()) { logger.debug("Save UserAccount with ID: " + account.getId()); } return account.getId(); }
From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java
public static JsonNode postToServer(String urlString, JSONObject objectToPost) { JsonNode ret = null;/* w w w . j a v a 2s .c o m*/ LOG.d("POST api request, url = " + urlString + " object = " + objectToPost.toString()); HttpParams myParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT); HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT); HttpClient httpclient = new DefaultHttpClient(myParams); httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT); HttpPost httppost = null; URL url = null; try { url = new URL(urlString); httppost = new HttpPost(url.toString()); httppost.setHeader("Content-type", "application/json"); httppost.setHeader("Accept", ACCEPT); httppost.setHeader("LANGUAGE_CODE", IbikeApplication.getLanguageString()); StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8);// , HTTP.UTF_8 se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httppost.setEntity(se); HttpResponse response = httpclient.execute(httppost); String serverResponse = EntityUtils.toString(response.getEntity()); LOG.d("API response = " + serverResponse); ret = Util.stringToJsonNode(serverResponse); } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) { LOG.e(e.getLocalizedMessage()); } } return ret; }
From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java
public static JsonNode putToServer(String urlString, JSONObject objectToPost) { JsonNode ret = null;//w w w. ja v a 2 s. c om LOG.d("PUT api request, url = " + urlString); HttpParams myParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT); HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT); HttpClient httpclient = new DefaultHttpClient(myParams); httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT); HttpPut httput = null; URL url = null; try { url = new URL(urlString); httput = new HttpPut(url.toString()); httput.setHeader("Content-type", "application/json"); httput.setHeader("Accept", ACCEPT); httput.setHeader("LANGUAGE_CODE", IbikeApplication.getLanguageString()); StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httput.setEntity(se); HttpResponse response = httpclient.execute(httput); String serverResponse = EntityUtils.toString(response.getEntity()); LOG.d("API response = " + serverResponse); ret = Util.stringToJsonNode(serverResponse); } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) { LOG.e(e.getLocalizedMessage()); } } return ret; }
From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java
public static JsonNode deleteFromServer(String urlString, JSONObject objectToPost) { JsonNode ret = null;//w ww .j a v a 2s .c o m LOG.d("DELETE api request, url = " + urlString); HttpParams myParams = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT); HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT); HttpClient httpclient = new DefaultHttpClient(myParams); httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT); HTTPDeleteWithBody httpdelete = null; URL url = null; try { url = new URL(urlString); httpdelete = new HTTPDeleteWithBody(url.toString()); httpdelete.setHeader("Content-type", "application/json"); httpdelete.setHeader("Accept", ACCEPT); httpdelete.setHeader("LANGUAGE_CODE", IbikeApplication.getLanguageString()); StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8); se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); httpdelete.setEntity(se); HttpResponse response = httpclient.execute(httpdelete); String serverResponse = EntityUtils.toString(response.getEntity()); LOG.d("API response = " + serverResponse); ret = Util.stringToJsonNode(serverResponse); } catch (Exception e) { if (e != null && e.getLocalizedMessage() != null) LOG.e(e.getLocalizedMessage()); } return ret; }