List of usage examples for org.json JSONObject put
public JSONObject put(String key, Object value) throws JSONException
From source file:com.liferay.mobile.android.v62.resourcepermission.ResourcePermissionService.java
public void setIndividualResourcePermissions(long groupId, long companyId, String name, String primKey, JSONObject roleIdsToActionIds) throws Exception { JSONObject _command = new JSONObject(); try {/*from w w w .j av a 2s. co m*/ JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("companyId", companyId); _params.put("name", checkNull(name)); _params.put("primKey", checkNull(primKey)); _params.put("roleIdsToActionIds", checkNull(roleIdsToActionIds)); _command.put("/resourcepermission/set-individual-resource-permissions", _params); } catch (JSONException _je) { throw new Exception(_je); } session.invoke(_command); }
From source file:com.liferay.mobile.android.v62.resourcepermission.ResourcePermissionService.java
public void setIndividualResourcePermissions(long groupId, long companyId, String name, String primKey, long roleId, JSONArray actionIds) throws Exception { JSONObject _command = new JSONObject(); try {/*w w w.ja v a2s .c o m*/ JSONObject _params = new JSONObject(); _params.put("groupId", groupId); _params.put("companyId", companyId); _params.put("name", checkNull(name)); _params.put("primKey", checkNull(primKey)); _params.put("roleId", roleId); _params.put("actionIds", checkNull(actionIds)); _command.put("/resourcepermission/set-individual-resource-permissions", _params); } catch (JSONException _je) { throw new Exception(_je); } session.invoke(_command); }
From source file:com.yanzhenjie.nohttp.HttpHeaders.java
@Override public final String toJSONString() { JSONObject jsonObject = new JSONObject(); Set<Map.Entry<String, List<String>>> entrySet = entrySet(); for (Map.Entry<String, List<String>> entry : entrySet) { String key = entry.getKey(); List<String> values = entry.getValue(); JSONArray value = new JSONArray(values); try {/*ww w . j a v a 2 s.c om*/ jsonObject.put(key, value); } catch (JSONException e) { Logger.w(e); } } return jsonObject.toString(); }
From source file:net.iubris.ipc_d3.cap.CamelizeSomeFieldsAndExtractInformazioniStoricheDates.java
private JSONArray adjustTimeAndTipiSpecifici(String dataAsCSV) throws ParseException { JSONArray jsonArray = CDL.toJSONArray(dataAsCSV); int length = jsonArray.length(); JSONArray jsonArrayNew = new JSONArray(); for (int i = 0; i < length; i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); JSONObject jsonObjectNew = new JSONObject(); jsonObjectNew.put("nome", jsonObject.getString("nome")); jsonObjectNew.put("indirizzo", jsonObject.getString("indirizzo")); jsonObjectNew.put("numeroCivico", jsonObject.getString("numero-civico")); jsonObjectNew.put("cap", jsonObject.getString("cap")); jsonObjectNew.put("quartiere", jsonObject.getString("quartiere")); jsonObjectNew.put("citta", jsonObject.getString("citta")); jsonObjectNew.put("geolocazione", jsonObject.getString("geolocazione")); jsonObjectNew.put("telefono", jsonObject.getString("telefono")); jsonObjectNew.put("mobile", jsonObject.getString("mobile")); jsonObjectNew.put("email", jsonObject.getString("email")); jsonObjectNew.put("web", jsonObject.getString("web")); jsonObjectNew.put("tipi", jsonObject.getString("tipi")); jsonObjectNew.put("tipiSpecifici", jsonObject.getString("tipi-specifici")); // jsonObjectNew.put("tipiSpecificiReduced", getTipiReduced(jsonObject)); // jsonObjectNew.put("times", getTimes(jsonObject)); LinkedList<String> date = findNumbers(jsonObject.getString("luogo-da-visitare.informazioni_storiche")); String dateString = date.toString().replace("[", "").replace("]", ""); jsonObjectNew.put("luoghiDaVisitare.informazioniStoriche.date", dateString); jsonArrayNew.put(jsonObjectNew); }// w w w. j a v a2 s . c om return jsonArrayNew; }
From source file:net.iubris.ipc_d3.cap.CamelizeSomeFieldsAndExtractInformazioniStoricheDates.java
private JSONArray getTimes(JSONObject jsonObject) throws ParseException { DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); String date = "1970-01-01"; JSONArray times = new JSONArray(); String apertura = jsonObject.getString("apertura"); long startingTimeEpoch = 0; if (apertura.isEmpty()) apertura = "19.00"; // default startingTimeEpoch = sdf.parse(date + " " + apertura.replace(".", ":")).getTime(); String chiusura = jsonObject.getString("chiusura"); long endingTimeEpoch = 0; if (chiusura.isEmpty()) chiusura = "1.00"; // default double parsedEndingTime = Double.parseDouble(chiusura); if (parsedEndingTime >= 0f && parsedEndingTime < 6f) // we are in next day date = "1970-01-02"; endingTimeEpoch = sdf.parse(date + " " + chiusura.replace(".", ":")).getTime(); String startingTimeEpoched = "" + startingTimeEpoch; String endingTimeEpoched = "" + endingTimeEpoch; JSONObject et = new JSONObject(); et.put("starting_time", startingTimeEpoched); et.put("ending_time", endingTimeEpoched); times.put(et);//from ww w .j a v a 2s . c o m return times; }
From source file:net.zorgblub.typhon.dto.PageOffsets.java
public String toJSON() throws JSONException { JSONObject jsonObject = new JSONObject(); jsonObject.put(Fields.fontFamily.name(), this.fontFamily); jsonObject.put(Fields.fontSize.name(), this.fontSize); jsonObject.put(Fields.vMargin.name(), this.vMargin); jsonObject.put(Fields.hMargin.name(), this.hMargin); jsonObject.put(Fields.lineSpacing.name(), this.lineSpacing); jsonObject.put(Fields.fullScreen.name(), this.fullScreen); jsonObject.put(Fields.allowStyling.name(), this.allowStyling); jsonObject.put(Fields.algorithmVersion.name(), this.algorithmVersion); jsonObject.put(Fields.offsets.name(), new JSONArray(this.offsets)); return jsonObject.toString(); }
From source file:com.phonegap.plugin.ChildBrowser.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. * @return A PluginResult object with a status and message. *//*ww w .j ava 2s . co m*/ public PluginResult execute(String action, JSONArray args, String callbackId) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { if (action.equals("showWebPage")) { this.browserCallbackId = callbackId; // If the ChildBrowser is already open then throw an error if (dialog != null && dialog.isShowing()) { return new PluginResult(PluginResult.Status.ERROR, "ChildBrowser is already open"); } result = this.showWebPage(args.getString(0), args.optJSONObject(1)); if (result.length() > 0) { status = PluginResult.Status.ERROR; return new PluginResult(status, result); } else { PluginResult pluginResult = new PluginResult(status, result); pluginResult.setKeepCallback(true); return pluginResult; } } else if (action.equals("close")) { closeDialog(); JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); PluginResult pluginResult = new PluginResult(status, obj); pluginResult.setKeepCallback(false); return pluginResult; } else if (action.equals("openExternal")) { result = this.openExternal(args.getString(0), args.optBoolean(1)); if (result.length() > 0) { status = PluginResult.Status.ERROR; } } else { status = PluginResult.Status.INVALID_ACTION; } return new PluginResult(status, result); } catch (JSONException e) { return new PluginResult(PluginResult.Status.JSON_EXCEPTION); } }
From source file:com.phonegap.plugin.ChildBrowser.java
/** * Display a new browser with the specified URL. * * @param url The url to load. * @param jsonObject /*from ww w .ja v a 2 s. c om*/ */ public String showWebPage(final String url, JSONObject options) { // Determine if we should hide the location bar. if (options != null) { showLocationBar = options.optBoolean("showLocationBar", true); } // Create dialog in new thread Runnable runnable = new Runnable() { public void run() { dialog = new Dialog(ctx.getContext(), android.R.style.Theme_Translucent_NoTitleBar); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCancelable(true); dialog.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(DialogInterface dialog) { try { JSONObject obj = new JSONObject(); obj.put("type", CLOSE_EVENT); sendUpdate(obj, false); } catch (JSONException e) { Log.d(LOG_TAG, "Should never happen"); } } }); LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams forwardParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams editParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1.0f); LinearLayout.LayoutParams closeParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LinearLayout.LayoutParams wvParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); LinearLayout main = new LinearLayout(ctx.getContext()); main.setOrientation(LinearLayout.VERTICAL); LinearLayout toolbar = new LinearLayout(ctx.getContext()); toolbar.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); toolbar.setOrientation(LinearLayout.HORIZONTAL); ImageButton back = new ImageButton(ctx.getContext()); back.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goBack(); } }); back.setId(1); try { back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } back.setLayoutParams(backParams); ImageButton forward = new ImageButton(ctx.getContext()); forward.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { goForward(); } }); forward.setId(2); try { forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } forward.setLayoutParams(forwardParams); edittext = new EditText(ctx.getContext()); edittext.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { navigate(edittext.getText().toString()); return true; } return false; } }); edittext.setId(3); edittext.setSingleLine(true); edittext.setText(url); edittext.setLayoutParams(editParams); ImageButton close = new ImageButton(ctx.getContext()); close.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { closeDialog(); } }); close.setId(4); try { close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png")); } catch (IOException e) { Log.e(LOG_TAG, e.getMessage(), e); } close.setLayoutParams(closeParams); webview = new WebView(ctx.getContext()); webview.setWebChromeClient(new WebChromeClient()); WebViewClient client = new ChildBrowserClient(edittext); webview.setWebViewClient(client); WebSettings settings = webview.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setBuiltInZoomControls(true); settings.setPluginsEnabled(true); settings.setDomStorageEnabled(true); webview.loadUrl(url); webview.setId(5); webview.setInitialScale(0); webview.setLayoutParams(wvParams); webview.requestFocus(); webview.requestFocusFromTouch(); toolbar.addView(back); toolbar.addView(forward); toolbar.addView(edittext); toolbar.addView(close); if (getShowLocationBar()) { main.addView(toolbar); } main.addView(webview); WindowManager.LayoutParams lp = new WindowManager.LayoutParams(); lp.copyFrom(dialog.getWindow().getAttributes()); lp.width = WindowManager.LayoutParams.FILL_PARENT; lp.height = WindowManager.LayoutParams.FILL_PARENT; dialog.setContentView(main); dialog.show(); dialog.getWindow().setAttributes(lp); } private Bitmap loadDrawable(String filename) throws java.io.IOException { InputStream input = ctx.getAssets().open(filename); return BitmapFactory.decodeStream(input); } }; this.ctx.runOnUiThread(runnable); return ""; }
From source file:org.b3log.solo.event.symphony.CommentSender.java
@Override public void action(final Event<JSONObject> event) throws EventException { final JSONObject data = event.getData(); LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]", new Object[] { event.getType(), data, ArticleSender.class.getName() }); try {//from w w w . j ava2s .c o m final JSONObject originalComment = data.getJSONObject(Comment.COMMENT); final JSONObject preference = preferenceQueryService.getPreference(); if (null == preference) { throw new EventException("Not found preference"); } final String blogHost = preference.getString(Preference.BLOG_HOST).toLowerCase(); if (blogHost.contains("localhost")) { LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not send this comment[id={0}] to Symphony", new Object[] { originalComment.getString(Keys.OBJECT_ID) }); return; } final HTTPRequest httpRequest = new HTTPRequest(); httpRequest.setURL(ADD_COMMENT_URL); httpRequest.setRequestMethod(HTTPRequestMethod.PUT); final JSONObject requestJSONObject = new JSONObject(); final JSONObject comment = new JSONObject(); comment.put("commentId", originalComment.optString(Keys.OBJECT_ID)); comment.put("commentAuthorName", originalComment.getString(Comment.COMMENT_NAME)); comment.put("commentAuthorEmail", originalComment.getString(Comment.COMMENT_EMAIL)); comment.put(Comment.COMMENT_CONTENT, originalComment.getString(Comment.COMMENT_CONTENT)); comment.put("articleId", originalComment.getString(Comment.COMMENT_ON_ID)); requestJSONObject.put(Comment.COMMENT, comment); requestJSONObject.put("clientVersion", SoloServletListener.VERSION); requestJSONObject.put("clientRuntimeEnv", Latkes.getRuntimeEnv().name()); requestJSONObject.put("clientName", "B3log Solo"); requestJSONObject.put("clientHost", blogHost); requestJSONObject.put("clientAdminEmail", preference.optString(Preference.ADMIN_EMAIL)); requestJSONObject.put("userB3Key", preference.optString(Preference.KEY_OF_SOLO)); httpRequest.setPayload(requestJSONObject.toString().getBytes("UTF-8")); urlFetchService.fetchAsync(httpRequest); } catch (final Exception e) { LOGGER.log(Level.SEVERE, "Sends a comment to Symphony error: {0}", e.getMessage()); } LOGGER.log(Level.FINER, "Sent a comment to Symphony"); }
From source file:de.dmxcontrol.executor.EntityExecutor.java
public void Send() { try {//from w w w .j a v a2 s . c o m JSONObject o = new JSONObject(); o.put("Type", NetworkID); o.put("GUID", this.guid); o.put("Name", this.getName()); o.put("Value", (double) this.value); o.put("Flash", this.flash); o.put("Number", this.getId()); if (this.doGO) { o.put("GO", true); } if (this.doBreakBack) { o.put("BreakBack", true); } if (this.doStop) { o.put("Stop", true); } ServiceFrontend.get().sendMessage(o.toString().getBytes()); o = null; if (o == null) { ; } return; } catch (Exception e) { Log.e("UDP Send: ", e.getMessage()); DMXControlApplication.SaveLog(); } }