List of usage examples for org.json JSONObject getString
public String getString(String key) throws JSONException
From source file:account.management.controller.inventory.StockReportController.java
@Override public void initialize(URL url, ResourceBundle rb) { product_list = FXCollections.observableArrayList(); try {//w w w.j a v a2s.c om HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "all/products").asJson(); JSONArray array = res.getBody().getArray(); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); int id = obj.getInt("id"); String name = obj.getString("name"); float p_qty = Float.parseFloat(obj.get("p_qty").toString()); float s_qty = Float.parseFloat(obj.get("s_qty").toString()); double last_p_rate = obj.getDouble("last_p_rate"); double last_s_rate = obj.getDouble("last_s_rate"); double avg_p_rate = obj.getDouble("avg_p_rate"); double avg_s_rate = obj.getDouble("avg_s_rate"); product_list .add(new Product(id, name, p_qty, s_qty, last_p_rate, last_s_rate, avg_p_rate, avg_s_rate)); } } catch (Exception e) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setHeaderText(null); alert.setContentText("Sorry!! there is an error in the server. Please try again."); alert.setGraphic(new ImageView(new Image("resources/error.jpg"))); alert.showAndWait(); } }
From source file:account.management.controller.inventory.SellReportController.java
/** * Initializes the controller class.// w w w . j av a 2 s . co m */ @Override public void initialize(URL url, ResourceBundle rb) { new AutoCompleteComboBoxListener<>(item); item.setOnHiding((e) -> { Product a = item.getSelectionModel().getSelectedItem(); item.setEditable(false); item.getSelectionModel().select(a); }); item.setOnShowing((e) -> { item.setEditable(true); }); // get product list products_list = FXCollections.observableArrayList(); try { HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "all/products").asJson(); JSONArray array = res.getBody().getArray(); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); int id = obj.getInt("id"); String name = obj.getString("name"); products_list.add(new Product(id, name)); } this.item.getItems().addAll(products_list); } catch (Exception e) { Alert alert = new Alert(Alert.AlertType.ERROR); alert.setHeaderText(null); alert.setContentText("Sorry!! there is an error in the server. Please try again."); alert.setGraphic(new ImageView(new Image("resources/error.jpg"))); alert.showAndWait(); } }
From source file:account.management.controller.inventory.SellReportController.java
@FXML private void onShowReportButtonClick(ActionEvent event) { this.show.setDisable(true); try {/*from ww w . ja va 2 s . co m*/ String id = String.valueOf(this.item.getSelectionModel().getSelectedItem().getId()); String start_date = "1980-01-01", end_date = "2050-12-31"; start_date = new SimpleDateFormat("yyyy-MM-dd") .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.start.getValue().toString())); end_date = new SimpleDateFormat("yyyy-MM-dd") .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.end.getValue().toString())); HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "report/ledger/sell").queryString("id", id) .queryString("start", start_date).queryString("end", end_date).asJson(); JSONArray array = res.getBody().getArray(); System.out.println(array); Vector v = new Vector(); HashMap params = new HashMap(); params.put("date", "From " + new SimpleDateFormat("dd-MM-yyyy") .format(new SimpleDateFormat("yyyy-MM-dd").parse(start_date)) + " To " + new SimpleDateFormat("dd-MM-yyyy") .format(new SimpleDateFormat("yyyy-MM-dd").parse(end_date))); params.put("item_name", "Purchase report of " + this.item.getSelectionModel().getSelectedItem().getName()); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); String date = obj.getString("date"); String quantity = obj.get("quantity").toString(); String rate = obj.get("rate").toString(); v.add(new SellPurchaseLedger(date, quantity, rate)); } Report report = new Report(); report.getReport("src\\report\\SellPurchaseLedger.jrxml", new JRBeanCollectionDataSource(v), params, "Sell Report"); report.getReport("src\\report\\DepositVoucher.jrxml", new JRBeanCollectionDataSource(v), params, "Deposit Voucher"); this.show.setDisable(false); } catch (Exception e) { System.out.println("Exception in show report button click"); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setHeaderText(null); alert.setContentText("Sorry!! there is an error. Please try again."); alert.setGraphic(new ImageView(new Image("resources/error.jpg"))); alert.showAndWait(); } }
From source file:account.management.controller.inventory.ProductWiseInventoryReportController.java
@FXML private void onShowReportClick(ActionEvent event) { this.show.setDisable(true); try {// w w w .j ava2 s .com String id = String.valueOf(this.item.getSelectionModel().getSelectedItem().getId()); String start_date = "1980-01-01", end_date = "2050-12-31"; start_date = new SimpleDateFormat("yyyy-MM-dd") .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.start.getValue().toString())); end_date = new SimpleDateFormat("yyyy-MM-dd") .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.end.getValue().toString())); HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "report/product/sellPurchase") .queryString("id", id).queryString("start", start_date).queryString("end", end_date).asJson(); JSONArray array = res.getBody().getArray(); Vector v = new Vector(); HashMap params = new HashMap(); params.put("date", "From " + new SimpleDateFormat("dd-MM-yyyy") .format(new SimpleDateFormat("yyyy-MM-dd").parse(start_date)) + " To " + new SimpleDateFormat("dd-MM-yyyy") .format(new SimpleDateFormat("yyyy-MM-dd").parse(end_date))); params.put("item_name", "Inventory report of " + this.item.getSelectionModel().getSelectedItem().getName()); float total_p_qty = 0, total_s_qty = 0; double total_p_param = 0; for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); String date = obj.getString("date"); date = new SimpleDateFormat("dd-MM-yyyy").format(new SimpleDateFormat("yyyy-MM-dd").parse(date)); String p_qty = obj.get("p_qty").toString() == "null" ? "-" : obj.get("p_qty").toString(); String p_rate = obj.get("p_rate").toString() == "null" ? "-" : obj.get("p_rate").toString(); String p_price = obj.get("p_total").toString() == "null" ? "-" : obj.get("p_total").toString(); String s_qty = obj.get("s_qty").toString() == "null" ? "-" : obj.get("s_qty").toString(); String s_rate = obj.get("s_rate").toString() == "null" ? "-" : obj.get("s_rate").toString(); String s_price = obj.get("s_total").toString() == "null" ? "-" : obj.get("s_total").toString(); System.out.println(s_price); v.add(new IndividualProductReport(date, p_qty, p_rate, p_price, s_qty, s_rate, s_price)); if (!p_qty.equals("-")) { total_p_qty += Float.parseFloat(p_qty); } if (!s_qty.equals("-")) { total_s_qty += Float.parseFloat(s_qty); } if (!p_price.equals("-")) { total_p_param += Float.parseFloat(p_price); } } params.put("closing_qty", String.valueOf(total_p_qty - total_s_qty)); System.out.println(total_p_qty); params.put("closing_rate", String.valueOf(total_p_param / total_p_qty)); params.put("closing_total", String.valueOf((total_p_qty - total_s_qty) * (total_p_param / total_p_qty))); Report report = new Report(); report.getReport("src\\report\\IndiviualProductPurchaseSellReport.jrxml", new JRBeanCollectionDataSource(v), params, "Product Wise Inventory Report"); this.show.setDisable(false); } catch (Exception e) { System.out.println("Exception in show report button click"); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setHeaderText(null); alert.setContentText("Sorry!! there is an error. Please try again."); alert.setGraphic(new ImageView(new Image("resources/error.jpg"))); alert.showAndWait(); } }
From source file:account.management.controller.inventory.InsertStockController.java
/** * Initializes the controller class.//from w w w . j a v a 2s. c o m */ @Override public void initialize(URL url, ResourceBundle rb) { // get product list products_list = FXCollections.observableArrayList(); try { HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "all/products").asJson(); JSONArray array = res.getBody().getArray(); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); int id = obj.getInt("id"); String name = obj.getString("name"); float p_qty = Float.parseFloat(obj.get("p_qty").toString()); float s_qty = Float.parseFloat(obj.get("s_qty").toString()); double last_p_rate = obj.getDouble("last_p_rate"); double last_s_rate = obj.getDouble("last_s_rate"); double avg_p_rate = obj.getDouble("avg_p_rate"); double avg_s_rate = obj.getDouble("avg_s_rate"); products_list .add(new Product(id, name, p_qty, s_qty, last_p_rate, last_s_rate, avg_p_rate, avg_s_rate)); } addRow(); } catch (Exception e) { } // voucher type (purchase/sell) this.voucher_type.getItems().addAll("Purchase", "Sell"); this.voucher_type.getSelectionModel().select("Sell"); }
From source file:at.zone.madeleine.ir.PixlinqSearch.java
private String parsePixlinqResponse(String response) { JSONObject responseObject;//from www. j a va 2 s .com String result = null; if (response != null) { try { responseObject = (JSONObject) new JSONTokener(response).nextValue(); JSONArray matches = responseObject.getJSONArray("matches"); JSONArray errors = responseObject.getJSONArray("errors"); if (matches.length() > 0) { JSONObject match = matches.getJSONObject(0); String title = match.getString("title"); String message = match.getString("message"); String sanatizedMessage = message.split("\\.")[0]; result = sanatizedMessage; } } catch (JSONException e) { e.printStackTrace(); } } else { result = null; } return result; }
From source file:account.management.controller.inventory.PurchaseReportController.java
@FXML private void onShowReportButtonClick(ActionEvent event) { this.show.setDisable(true); try {//from ww w.j ava 2s. co m String id = String.valueOf(this.item.getSelectionModel().getSelectedItem().getId()); String start_date = "1980-01-01", end_date = "2050-12-31"; start_date = new SimpleDateFormat("yyyy-MM-dd") .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.start.getValue().toString())); end_date = new SimpleDateFormat("yyyy-MM-dd") .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.end.getValue().toString())); HttpResponse<JsonNode> res = Unirest.get(MetaData.baseUrl + "report/ledger/purchase") .queryString("id", id).queryString("start", start_date).queryString("end", end_date).asJson(); JSONArray array = res.getBody().getArray(); System.out.println(array); Vector v = new Vector(); HashMap params = new HashMap(); params.put("date", "From " + new SimpleDateFormat("dd-MM-yyyy") .format(new SimpleDateFormat("yyyy-MM-dd").parse(start_date)) + " To " + new SimpleDateFormat("dd-MM-yyyy") .format(new SimpleDateFormat("yyyy-MM-dd").parse(end_date))); params.put("item_name", "Purchase report of " + this.item.getSelectionModel().getSelectedItem().getName()); for (int i = 0; i < array.length(); i++) { JSONObject obj = array.getJSONObject(i); String date = obj.getString("date"); String quantity = obj.get("quantity").toString(); String rate = obj.get("rate").toString(); v.add(new SellPurchaseLedger(date, quantity, rate)); } Report report = new Report(); report.getReport("src\\report\\SellPurchaseLedger.jrxml", new JRBeanCollectionDataSource(v), params, "Purchase Report"); this.show.setDisable(false); } catch (Exception e) { System.out.println("Exception in show report button click"); Alert alert = new Alert(Alert.AlertType.ERROR); alert.setHeaderText(null); alert.setContentText("Sorry!! there is an error. Please try again."); alert.setGraphic(new ImageView(new Image("resources/error.jpg"))); alert.showAndWait(); } }
From source file:at.tugraz.ist.catroid.web.ServerCalls.java
public String uploadProject(String projectName, String projectDescription, String zipFileString, String userEmail, String language, String token) throws WebconnectionException { if (emailForUiTests != null) { userEmail = emailForUiTests;//from ww w . ja va 2 s . co m } try { String md5Checksum = Utils.md5Checksum(new File(zipFileString)); HashMap<String, String> postValues = new HashMap<String, String>(); postValues.put(PROJECT_NAME_TAG, projectName); postValues.put(PROJECT_DESCRIPTION_TAG, projectDescription); postValues.put(USER_EMAIL, userEmail); postValues.put(PROJECT_CHECKSUM_TAG, md5Checksum.toLowerCase()); postValues.put(Constants.TOKEN, token); if (language != null) { postValues.put(USER_LANGUAGE, language); } String serverUrl = useTestUrl ? TEST_FILE_UPLOAD_URL : FILE_UPLOAD_URL; Log.v(TAG, "url to upload: " + serverUrl); resultString = connection.doHttpPostFileUpload(serverUrl, postValues, FILE_UPLOAD_TAG, zipFileString); JSONObject jsonObject = null; int statusCode = 0; Log.v(TAG, "result string: " + resultString); jsonObject = new JSONObject(resultString); statusCode = jsonObject.getInt("statusCode"); String serverAnswer = jsonObject.getString("answer"); if (statusCode == 200) { return serverAnswer; } else { throw new WebconnectionException(statusCode, serverAnswer); } } catch (JSONException e) { e.printStackTrace(); throw new WebconnectionException(WebconnectionException.ERROR_JSON); } catch (IOException e) { e.printStackTrace(); throw new WebconnectionException(WebconnectionException.ERROR_NETWORK); } }
From source file:com.google.cast.samples.tictactoe.GameChannel.java
/** * Processes all Text messages received from the receiver device and performs the appropriate * action for the message. Recognizable messages are of the form: * * <ul>/*from w w w . j a v a 2 s .com*/ * <li> KEY_JOINED: a player joined the current game * <li> KEY_MOVED: a player made a move * <li> KEY_ENDGAME: the game has ended in one of the END_STATE_* states * <li> KEY_ERROR: a game error has occurred * <li> KEY_BOARD_LAYOUT_RESPONSE: the board has been laid out in some new configuration * </ul> * * <p>No other messages are recognized. */ @Override public void onMessageReceived(CastDevice castDevice, String namespace, String message) { try { Log.d(TAG, "onTextMessageReceived: " + message); JSONObject payload = new JSONObject(message); Log.d(TAG, "payload: " + payload); if (payload.has(KEY_EVENT)) { String event = payload.getString(KEY_EVENT); if (KEY_JOINED.equals(event)) { Log.d(TAG, "JOINED"); try { String player = payload.getString(KEY_PLAYER); String opponentName = payload.getString(KEY_OPPONENT); onGameJoined(player, opponentName); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_MOVED.equals(event)) { Log.d(TAG, "MOVED"); try { String player = payload.getString(KEY_PLAYER); int row = payload.getInt(KEY_ROW); int column = payload.getInt(KEY_COLUMN); boolean isGameOver = payload.getBoolean(KEY_GAME_OVER); onGameMove(player, row, column, isGameOver); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_ENDGAME.equals(event)) { Log.d(TAG, "ENDGAME"); try { String endState = payload.getString(KEY_END_STATE); int winningLocation = -1; if (END_STATE_ABANDONED.equals(endState) == false) { winningLocation = payload.getInt(KEY_WINNING_LOCATION); } onGameEnd(endState, winningLocation); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_ERROR.equals(event)) { Log.d(TAG, "ERROR"); try { String errorMessage = payload.getString(KEY_MESSAGE); onGameError(errorMessage); } catch (JSONException e) { e.printStackTrace(); } } else if (KEY_BOARD_LAYOUT_RESPONSE.equals(event)) { Log.d(TAG, "Board Layout"); int[][] boardLayout = new int[3][3]; try { JSONArray boardJSONArray = payload.getJSONArray(KEY_BOARD); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { boardLayout[i][j] = boardJSONArray.getInt(i * 3 + j); } } onGameBoardLayout(boardLayout); } catch (JSONException e) { e.printStackTrace(); } } } else { Log.w(TAG, "Unknown payload: " + payload); } } catch (JSONException e) { Log.w(TAG, "Message doesn't contain an expected key.", e); } }
From source file:com.example.cuisoap.agrimac.machineRegister.containerActivity.java
@Override public void onButtonClicked(JSONObject data, int from) { System.out.println(data.toString()); switch (from) { case 1:/*from w w w.ja va 2 s .co m*/ try { send_data.put("drive_type", data.getString("drive_type")); send_data.put("driver_name", data.getString("driver_name")); send_data.put("driver_age", data.getString("driver_age")); send_data.put("driver_gender", data.getString("driver_gender")); send_data.put("driver_license_type", data.getString("license_type")); //send_data.put("driver_license",data.getString("license_path")); filelist.put("driver_license", data.getString("license_path")); } catch (JSONException e) { e.printStackTrace(); } mPager.setCurrentItem(1); break; case 2: try { send_data.put("machine_type", data.getString("machine_type")); send_data.put("machine_name", data.getString("machine_name")); send_data.put("machine_power", data.getString("machine_power")); send_data.put("passenger_num", data.getString("passenger_num")); send_data.put("machine_wheeldistance", data.getString("wheel_distance")); send_data.put("machine_checktime", data.getString("check_time")); send_data.put("machine_paytype", data.getString("pay_type")); send_data.put("machine_powertype", data.getString("power")); // send_data.put("machine_license1",data.getString("license_path1")); // send_data.put("machine_license2",data.getString("license_path2")); filelist.put("machine_license1", data.getString("license_path1")); filelist.put("machine_license2", data.getString("license_path2")); } catch (JSONException e) { e.printStackTrace(); } mPager.setCurrentItem(2); break; case 3: try { send_data.put("lease_month", data.getString("lease_month")); send_data.put("lease_time", data.getString("lease_time")); send_data.put("work_condition", data.getString("work_condition")); send_data.put("need_type", data.getString("need_type")); if (data.getString("need_type").equals("2")) send_data.put("need_item", data.getString("needItem")); send_data.put("house_type", data.getString("house_type")); } catch (JSONException e) { e.printStackTrace(); } /* Message e=Message.obtain(); JSONObject o=new JSONObject(); try { o.put("status","0"); o.put("id","1"); e.obj=o.toString(); e.setTarget(h); e.sendToTarget(); } catch (JSONException e1) { e1.printStackTrace(); }*/ new Thread(send).start(); //TODO ? } }