List of usage examples for org.json JSONObject toString
public String toString()
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 ww. ja v a2 s .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 {/* w w w . j a v a2 s. co 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(); } }
From source file:com.abeo.tia.noordin.AddCaseStep2of4.java
private void btnconfirm() { // Find the SharedPreferences pass Login value SharedPreferences prefLoginReturn = getSharedPreferences("LoginData", Context.MODE_PRIVATE); System.out.println("LOGIN DATA"); String userName = prefLoginReturn.getString("sUserName", ""); String category = prefLoginReturn.getString("sCategory", ""); System.out.println(category); String CardCode = prefLoginReturn.getString("CardCode", ""); System.out.println(CardCode); JSONObject jsonObject = new JSONObject(); // jsonObject.put("Category", "SPA"); try {// w ww .ja v a 2 s. co m // Find confirmation message // messageResult = jsonObject.getString("Result").toString(); jsonObject.put("CODE", ""); jsonObject.put("CARDCODE", CardCode); jsonObject.put("TITLETYPE", titleValue); jsonObject.put("TITLENO", Title.getText().toString()); jsonObject.put("LOTTYPE", LotType.getText().toString()); jsonObject.put("LOTNO", LotNo.getText().toString()); jsonObject.put("FORMERLY_KNOWN_AS", Knownas.getText().toString()); jsonObject.put("BPM", Pekan.getText().toString()); jsonObject.put("STATE", stateval); jsonObject.put("AREA", Nageri.getText().toString()); jsonObject.put("LOTAREA", LotArea.getText().toString()); jsonObject.put("LASTUPDATEDON", LastUpdate.getText().toString()); jsonObject.put("DEVELOPER", developerValue); jsonObject.put("DVLPR_CODE", developerValue_id); jsonObject.put("PROJECT_CODE", ProjectValue_id); jsonObject.put("PROJECTNAME", ProjectValue); jsonObject.put("DEVLICNO", DevLicense.getText().toString()); jsonObject.put("DEVSOLICTOR", solicitorValue); jsonObject.put("DVLPR_SOL_CODE", solicitorValue_id); jsonObject.put("DVLPR_LOC", SolicitorLoc.getText().toString()); jsonObject.put("LSTCHG_BANKCODE", bankValue_id); jsonObject.put("LSTCHG_BANKNAME", bankValue); jsonObject.put("LSTCHG_BRANCH", Branch.getText().toString()); jsonObject.put("LSTCHG_PANO", PAName.getText().toString()); jsonObject.put("LSTCHG_PRSTNO", PresentaionNo.getText().toString()); jsonObject.put("PurchasePrice", PurchasePrice.getText().toString()); if (QryGroup13.isChecked()) jsonObject.put("PROPERTYCHARGED", "Y"); else jsonObject.put("PROPERTYCHARGED", "N"); //arrOfJson.put(jsonObject); System.out.println("JsonArray:" + jsonObject.toString()); //upDateList(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } RequestParams params = new RequestParams(); params.put("sJsonInput", jsonObject.toString()); System.out.println("params"); System.out.println(params); dialog = ProgressDialog.show(AddCaseStep2of4.this, "", "Loading...", true); RestService.post(METHOD_ADD_CASE2, params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); System.out.println("onFailure"); dialog.dismiss(); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("onFailure"); System.out.println("AddCase2 Details Add Confirmed"); System.out.println(arg2); dialog.dismiss(); // Find status Response try { StatusResult = jsonResponse.getString("Result").toString(); messageDisplay = jsonResponse.getString("DisplayMessage").toString(); if (StatusResult.equals("SUCCESS")) { Intent iAddBack = new Intent(AddCaseStep2of4.this, AddCaseStep3of4.class); startActivity(iAddBack); Toast.makeText(AddCaseStep2of4.this, messageDisplay, Toast.LENGTH_SHORT).show(); } else if (jsonResponse.getString("CaseFileNo").toString() != "") { // Find Response for ListView try { jsonCaselist = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); /* * [ { "CaseFileNo": "1500000006", "RelatedFileNo": * "", "BranchCode": "", "FileOpenedDate": * "8/1/2015 12:00:00 AM", "IC": "3", "CaseType": * "SPA", "ClientName": "", "BankName": "", * "Branch": "", "LOTNo": "", "CaseAmount": "", * "UserCode": "", "Status": "OPEN", * "FileClosedDate": "" } ] */ CaseList_CaseFileNo = jsonResponse.getString("CaseFileNo").toString(); CaseList_RelatedFileNo = jsonResponse.getString("RelatedFileNo").toString(); CaseList_BranchCode = jsonResponse.getString("BranchCode").toString(); CaseList_FileOpenedDate = jsonResponse.getString("FileOpenedDate").toString(); CaseList_IC = jsonResponse.getString("IC").toString(); CaseList_CaseType = jsonResponse.getString("CaseType").toString(); CaseList_ClientName = jsonResponse.getString("ClientName").toString(); CaseList_BankName = jsonResponse.getString("BankName").toString(); // CaseList_Branch = // jsonResponse.getString("Branch").toString(); CaseList_LOTNo = jsonResponse.getString("LOTNo").toString(); CaseList_CaseAmount = jsonResponse.getString("CaseAmount").toString(); CaseList_UserCode = jsonResponse.getString("UserCode").toString(); CaseList_Status = jsonResponse.getString("Status").toString(); CaseList_FileClosedDate = jsonResponse.getString("FileClosedDate").toString(); // SEND JSON DATA INTO CASELIST HashMap<String, String> caseListProperty = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON CASE LIST"); caseListProperty.put("CaseFileNo_List", CaseList_CaseFileNo); System.out.println(CaseList_CaseFileNo); caseListProperty.put("RelatedFileNo_List", CaseList_RelatedFileNo); System.out.println(CaseList_RelatedFileNo); caseListProperty.put("BranchCode_List", CaseList_BranchCode); System.out.println(CaseList_BranchCode); caseListProperty.put("FileOpenedDate_List", CaseList_FileOpenedDate); System.out.println(CaseList_FileOpenedDate); caseListProperty.put("IC_List", CaseList_IC); System.out.println(CaseList_IC); caseListProperty.put("CaseType_List", CaseList_CaseType); System.out.println(CaseList_CaseType); caseListProperty.put("ClientName_List", CaseList_ClientName); System.out.println(CaseList_ClientName); caseListProperty.put("BankName_List", CaseList_BankName); System.out.println(CaseList_BankName); // caseListProperty.put("Branch_List",CaseList_Branch); // System.out.println(CaseList_Branch); caseListProperty.put("LOTNo_List", CaseList_LOTNo); System.out.println(CaseList_LOTNo); caseListProperty.put("CaseAmount_List", CaseList_CaseAmount); System.out.println(CaseList_CaseAmount); caseListProperty.put("UserCode_List", CaseList_UserCode); System.out.println(CaseList_UserCode); caseListProperty.put("Status_List", CaseList_Status); System.out.println(CaseList_Status); caseListProperty.put("FileClosedDate", CaseList_FileClosedDate); System.out.println(CaseList_FileClosedDate); System.out.println(" END SEND JSON CASE LIST"); jsonCaselist.add(caseListProperty); System.out.println("JSON CASELIST"); System.out.println(jsonCaselist); } } catch (JSONException e) { // TODO Auto-generated catc // block e.printStackTrace(); } //Toast.makeText(PropertyActivity.this, "Case Item Found", Toast.LENGTH_SHORT).show(); Intent intentList = new Intent(AddCaseStep2of4.this, PropertyRelatedCaseListActivity.class); intentList.putExtra("ProjectJsonList", jsonCaselist); startActivity(intentList); System.out.println(arg2); } else { Toast.makeText(AddCaseStep2of4.this, messageDisplay, Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("Addcase3 Details Add Response"); System.out.println(arg0); return null; } }); }
From source file:com.abeo.tia.noordin.AddCaseStep2of4.java
public void dropdownTitle() throws JSONException { RequestParams params = null;/*from w ww .ja v a 2 s.c om*/ params = new RequestParams(); JSONObject jsonObject = new JSONObject(); jsonObject.put("TableName", "@AE_PROPERTY"); jsonObject.put("FieldName", "TITLETYPE"); params.put("sJsonInput", jsonObject.toString()); RestService.post(TitleType_DROPDOWN, params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); System.out.println("Failed"); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("property Dropdown Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonlistProject = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); id = jsonResponse.getString("Id").toString(); name = jsonResponse.getString("Name").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> proList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON LIST"); proList.put("Id_T", id); System.out.println(name); proList.put("Name_T", name); System.out.println(name); System.out.println(" END SEND JSON PROPERTY LIST"); jsonlistProject.add(proList); System.out.println("JSON PROPERTY LIST"); System.out.println(jsonlistProject); } // Spinner set Array Data in Drop down sAdapPROJ = new SimpleAdapter(AddCaseStep2of4.this, jsonlistProject, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinnerpropertyTitleType.setAdapter(sAdapPROJ); /*for (int j = 0; j < jsonlistProject.size(); j++) { if (jsonlistProject.get(j).get("Id_T").equals(projectDetailResponse)) { TitleType_DROPDOWN.setSelection(j); break; } }*/ } catch (JSONException e) { // TODO Auto-generated // catc // block e.printStackTrace(); } } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("Property Dropdown Details parse Response"); System.out.println(arg0); return null; } }); }
From source file:com.abeo.tia.noordin.AddCaseStep2of4.java
public void dropdownState() throws JSONException { RequestParams params = null;//from ww w.j a v a2 s .co m params = new RequestParams(); JSONObject jsonObject = new JSONObject(); jsonObject.put("TableName", "OCRD"); jsonObject.put("FieldName", "STATE"); params.put("sJsonInput", jsonObject.toString()); RestService.post(METHOD_PROPERTY_STATE, params, new BaseJsonHttpResponseHandler<String>() { @Override public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) { // TODO Auto-generated method stub System.out.println(arg3); } @Override public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) { // TODO Auto-generated method stub System.out.println("State Dropdown Success Details "); System.out.println(arg2); try { arrayResponse = new JSONArray(arg2); // Create new list jsonliststate = new ArrayList<HashMap<String, String>>(); for (int i = 0; i < arrayResponse.length(); i++) { jsonResponse = arrayResponse.getJSONObject(i); id = jsonResponse.getString("Id").toString(); name = jsonResponse.getString("Name").toString(); // SEND JSON DATA INTO SPINNER TITLE LIST HashMap<String, String> proList = new HashMap<String, String>(); // Send JSON Data to list activity System.out.println("SEND JSON LIST"); proList.put("Id_T", id); System.out.println(name); proList.put("Name_T", name); System.out.println(name); System.out.println(" END SEND JSON PROPERTY LIST"); jsonliststate.add(proList); System.out.println("JSON STATE LIST"); System.out.println(jsonliststate); } // Spinner set Array Data in Drop down sAdaparea = new SimpleAdapter(AddCaseStep2of4.this, jsonliststate, R.layout.spinner_item, new String[] { "Id_T", "Name_T" }, new int[] { R.id.Id, R.id.Name }); spinnerpropertySTATE.setAdapter(sAdaparea); for (int j = 0; j < jsonliststate.size(); j++) { if (jsonliststate.get(j).get("Id_T").equals(statevalue)) { spinnerpropertySTATE.setSelection(j); break; } } } catch (JSONException e) { // TODO Auto-generated // catc // block e.printStackTrace(); } } @Override protected String parseResponse(String arg0, boolean arg1) throws Throwable { // Get Json response arrayResponse = new JSONArray(arg0); jsonResponse = arrayResponse.getJSONObject(0); System.out.println("State Dropdown Details parse Response"); System.out.println(arg0); return null; } }); }
From source file:com.util.httpAccount.java
public Account getAccountObject(String tel) { String telefono = tel.replace("-", ""); System.out.println("OBTENER SOLO UN ARRAY DE CADENA JSON"); //String myURL = "http://192.168.5.44/app_dev.php/cus/getaccount/50241109321.json"; String myURL = "http://192.168.5.44/app_dev.php/cus/getaccount/" + telefono + ".json"; System.out.println("Requested URL:" + myURL); StringBuilder sb = new StringBuilder(); URLConnection urlConn = null; InputStreamReader in = null;//from w ww . j a v a 2s .co m Account account = new Account(); try { URL url = new URL(myURL); urlConn = url.openConnection(); if (urlConn != null) { urlConn.setReadTimeout(60 * 1000); if (urlConn != null && urlConn.getInputStream() != null) { in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset()); BufferedReader bufferedReader = new BufferedReader(in); if (bufferedReader != null) { int cp; while ((cp = bufferedReader.read()) != -1) { sb.append((char) cp); } bufferedReader.close(); } } String jsonResult = sb.toString(); // System.out.println(sb.toString()); //System.out.println("\n\n--------------------OBTENEMOS OBJETO JSON NATIVO DE LA PAGINA, USAMOS EL ARRAY DATA---------------------------\n\n"); JSONObject objJason = new JSONObject(jsonResult); JSONArray dataJson = new JSONArray(); dataJson = objJason.getJSONArray("data"); //System.out.println("objeto normal 1 "+dataJson.toString()); // // // System.out.println("\n\n--------------------CREAMOS UN STRING JSON2 REEMPLAZANDO LOS CORCHETES QUE DAN ERROR---------------------------\n\n"); String jsonString2 = dataJson.toString(); String temp = dataJson.toString(); temp = jsonString2.replace("[", ""); jsonString2 = temp.replace("]", ""); // System.out.println("new json string"+jsonString2); JSONObject objJson2 = new JSONObject(jsonString2); // System.out.println("el objeto simple json es " + objJson2.toString()); // System.out.println("\n\n--------------------CREAMOS UN OBJETO JSON CON EL ARRAR ACCOUN---------------------------\n\n"); String account1 = objJson2.optString("account"); // System.out.println(account1); JSONObject objJson3 = new JSONObject(account1); // System.out.println("el ULTIMO OBJETO SIMPLE ES " + objJson3.toString()); // System.out.println("\n\n--------------------EMPEZAMOS A RECIBIR LOS PARAMETROS QUE HAY EN EL OBJETO JSON---------------------------\n\n"); String firstName = objJson3.getString("first_name"); System.out.println(firstName); System.out.println(objJson3.get("language_id")); // System.out.println("\n\n--------------------TRATAMOS DE PASAR TODO EL ACCOUNT A OBJETO JAVA---------------------------\n\n"); Gson gson = new Gson(); account = gson.fromJson(objJson3.toString(), Account.class); //System.out.println(account.getFirst_name()); // System.out.println(account.getCreation()); account.setLanguaje_id(objJson3.get("language_id").toString()); account.setId(objJson3.get("id").toString()); account.setBalance(objJson3.get("balance").toString()); System.out.println("el id del account es " + account.getId()); } else { System.out.print("no se pudo conectar con el servidor"); account = null; } in.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("Exception while calling URL:" + myURL, e); } return account; }
From source file:biz.mosil.webtools.MosilWeb.java
/** * ? JsonString ?/*w w w.j av a 2s . com*/ * @return (String) <b>JsonString</b> Format: {"key1":"value1", "key2":"value2", ...} * */ public static final String parseToJsonString(Map<String, Object> _data) { String jsonString = ""; if (_data != null) { JSONObject json = new JSONObject(); try { for (Map.Entry<String, Object> data : _data.entrySet()) { json.put(data.getKey(), data.getValue()); } } catch (JSONException _ex) { Log.e(TAG, "Parse To JsonString Error: " + _ex.toString()); } jsonString = json.toString(); } return jsonString; }
From source file:wsclient.Hitagi.java
public void start() { try {/*from ww w. j ava 2 s . c o m*/ client = new WebsocketClientEndpoint(); } catch (Exception e) { JOptionPane.showMessageDialog(null, ": URISyntaxException"); } client.addMessageHandler(new WebsocketClientEndpoint.MessageHandler() { @Override public void handleMessage(JSONObject result) { String resultType = (String) result.get("type"); System.out.println("Incoming: " + result.toString()); if (resultType.equals("auth")) { String status = (String) result.get("status"); if (status.equals("ok")) { User me = new User(); me.setByJson(result); if (listener != null) listener.doAuth(me); } else { JOptionPane.showMessageDialog(null, " : " + result.get("reason")); } } else if (resultType.equals("joinroom")) { String status = (String) result.get("status"); if (status.equals("ok")) { Room r = new Room(); r.setByJson(result); if (listener != null) listener.doJoinroom(r); } else { JOptionPane.showMessageDialog(null, " : " + result.get("reason")); } } else if (resultType.equals("chat")) { ChatMessage message = new ChatMessage(); message.setByJson(result); if (listener != null) listener.doChat(message); } else { System.err.println("Unknown Type: " + resultType); } } }); client.go(); }
From source file:IoTatWork.AuCapTreeResource.java
@Get public Representation get() { System.out.println(this.dbUrl); graph = new OrientGraph(this.dbUrl); JsonRepresentation jsonReturn = null; Map<String, String> attributes = getQuery().getValuesMap(); System.out.println(attributes); if (attributes.containsKey("depth")) { depth = Integer.parseInt(attributes.get("depth")); }//w w w . ja v a2s. c o m String auCapRid = null; if (attributes.containsKey("id")) { System.out.println("#" + attributes.get("id")); if (checkExistNode("#" + attributes.get("id"))) { auCapRid = "#" + attributes.get("id"); } } else { auCapRid = getRootRid(); } if (auCapRid != null) { JSONObject jsonNodeTree = new JSONObject(); Vertex auCapNode = graph.getVertex(auCapRid); Object revokedSince = checkParentsRevocation(auCapNode); if (revokedSince != null) { getJsonNodeTree(auCapNode, jsonNodeTree, 0, true, revokedSince); } else { getJsonNodeTree(auCapNode, jsonNodeTree, 0, false, null); } System.out.println(jsonNodeTree.toString()); jsonReturn = new JsonRepresentation(jsonNodeTree); } graph.shutdown(); return jsonReturn; }
From source file:org.fabrican.extension.variable.provider.servlet.RequestsServlet.java
private void serviceRequest(String n, HttpServletRequest req, HttpServletResponse resp) throws Exception { String pKey = req.getParameter(PARAM_PRIMARY); String sKey = req.getParameter(PARAM_SECONDARY); RuleSet rs = RuleSetDAO.getInstance().getRuleSetByName(n); if (rs == null) { resp.setStatus(SC_NOT_FOUND);/* w ww.j ava2 s. c o m*/ return; } else { HashMap<String, String> hm = rs.evaluate(pKey, sKey); JSONObject jo = new JSONObject(); for (Entry<String, String> e : hm.entrySet()) { jo.put(e.getKey(), e.getValue()); } resp.setStatus(SC_OK); resp.getOutputStream().write(jo.toString().getBytes("utf-8")); } }