Example usage for org.json JSONObject JSONObject

List of usage examples for org.json JSONObject JSONObject

Introduction

In this page you can find the example usage for org.json JSONObject JSONObject.

Prototype

public JSONObject() 

Source Link

Document

Construct an empty JSONObject.

Usage

From source file:at.alladin.rmbt.db.QoSTestResult.java

/**
 * //from   ww w .  j  a va 2s.  c om
 * @return
 * @throws JSONException 
 */
public JSONObject toJson(UuidType exportType) throws JSONException {
    JSONObject json = new JSONObject();
    json.put("uid", getUid());
    json.put("test_type", getTestType());
    json.put("result", new JSONObject(getResults()));
    json.put("test_desc", getTestDescription());
    json.put("success_count", getSuccessCounter());
    json.put("failure_count", getFailureCounter());
    json.put("test_summary", String.valueOf(getTestSummary()));

    if (resultKeyMap != null && resultKeyMap.size() > 0) {
        json.put("test_result_keys", new JSONArray(resultKeyMap.keySet()));
        json.put("test_result_key_map", new JSONObject(resultKeyMap));
    }

    if (exportType.equals(UuidType.TEST_UUID)) {
        json.put("nn_test_uid", getQoSTestObjectiveId()); // TODO: remove backwards compatibility (<= 2.0.28/20028)
        json.put("qos_test_uid", getQoSTestObjectiveId());
        json.put("test_uid", getTestUid());
    }
    return json;
}

From source file:at.alladin.rmbt.db.QoSTestTypeDesc.java

/**
 * /*from www . ja  v a  2s.  c om*/
 * @return
 * @throws JSONException 
 */
public JSONObject toJson() {
    final JSONObject json = new JSONObject();

    try {
        if (getTestType() == null) {
            throw new IllegalArgumentException("test_type not found: " + getName());
        }
        json.put("test_type", getTestType().name());
        json.put("desc", getDescription());
        json.put("name", getName());
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    return json;
}

From source file:account.management.controller.inventory.InsertStockController.java

@FXML
private void onSaveButtonClick(ActionEvent event) {
    this.save.setDisable(true);
    try {/*from  ww w.j av  a  2s.co  m*/
        String date = new SimpleDateFormat("yyyy-MM-dd")
                .format(new SimpleDateFormat("yyyy-MM-dd").parse(this.date.getValue().toString()));
        JSONArray array = new JSONArray();
        for (int i = 0; i < this.conatiner.getChildren().size(); i++) {
            HBox row = (HBox) this.conatiner.getChildren().get(i);
            ComboBox<Product> item = (ComboBox) row.getChildren().get(0);
            TextField qty = (TextField) row.getChildren().get(1);
            TextField rate = (TextField) row.getChildren().get(2);

            JSONObject obj = new JSONObject();
            obj.put("id", item.getSelectionModel().getSelectedItem().getId());
            obj.put("quantity", qty.getText());
            obj.put("rate", rate.getText());

            array.put(obj);

        }

        Unirest.post(MetaData.baseUrl + "products/ledger")
                .field("voucher_type", this.voucher_type.getSelectionModel().getSelectedItem())
                .field("date", date).field("products", array).asString();
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setHeaderText(null);
        alert.setContentText("Ledger has been saved successfully!");
        alert.setGraphic(new ImageView(new Image("resources/success.jpg")));
        alert.showAndWait();
        this.save.setDisable(false);
    } catch (Exception ex) {
        Logger.getLogger(InsertStockController.class.getName()).log(Level.SEVERE, null, ex);
        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.alladin.rmbt.util.tools.InformationCollectorTool.java

/**
 * //from   w  w  w.jav a  2 s.c om
 * @param clean
 * @param relativeTimeStamp
 * @return
 */
public JSONObject getJsonObject(final boolean clean, long relativeTimeStamp) {
    try {
        JSONObject json = new JSONObject();
        for (CollectorHolder c : collectorList) {
            synchronized (c.collector) {
                json.put(c.collector.getJsonKey(),
                        c.collector.getJsonResult(clean, relativeTimeStamp, deltaTimeUnit));
            }
        }
        return json;
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:at.alladin.rmbt.db.TestStat.java

public JSONObject toJsonObject() throws JSONException {
    final JSONObject jsonObject = new JSONObject();
    jsonObject.put("cpu_usage", cpuUsage);
    jsonObject.put("mem_usage", memUsage);
    return jsonObject;
}

From source file:com.google.cast.samples.tictactoe.GameChannel.java

/**
 * Attempts to connect to an existing session of the game by sending a join command.
 *
 * @param name the name of the player that is joining
 *///from   www  .  ja v a2 s  .  com
public final void join(GoogleApiClient apiClient, String name) {
    try {
        Log.d(TAG, "join: " + name);
        JSONObject payload = new JSONObject();
        payload.put(KEY_COMMAND, KEY_JOIN);
        payload.put(KEY_NAME, name);
        sendMessage(apiClient, payload.toString());
    } catch (JSONException e) {
        Log.e(TAG, "Cannot create object to join a game", e);
    }
}

From source file:com.google.cast.samples.tictactoe.GameChannel.java

/**
 * Attempts to make a move by sending a command to place a piece in the given row and column.
 *///w  w w .  ja  va  2 s  . c o  m
public final void move(GoogleApiClient apiClient, final int row, final int column) {
    Log.d(TAG, "move: row:" + row + " column:" + column);
    try {
        JSONObject payload = new JSONObject();
        payload.put(KEY_COMMAND, KEY_MOVE);
        payload.put(KEY_ROW, row);
        payload.put(KEY_COLUMN, column);
        sendMessage(apiClient, payload.toString());
    } catch (JSONException e) {
        Log.e(TAG, "Cannot create object to send a move", e);
    }
}

From source file:com.google.cast.samples.tictactoe.GameChannel.java

/**
 * Sends a command to leave the current game.
 *///from w ww  . jav  a2s. c  o m
public final void leave(GoogleApiClient apiClient) {
    try {
        Log.d(TAG, "leave");
        JSONObject payload = new JSONObject();
        payload.put(KEY_COMMAND, KEY_LEAVE);
        sendMessage(apiClient, payload.toString());
    } catch (JSONException e) {
        Log.e(TAG, "Cannot create object to leave a game", e);
    }
}

From source file:com.google.cast.samples.tictactoe.GameChannel.java

/**
 * Sends a command requesting the current layout of the board.
 *///from   w  w  w  .  j a  v a2 s .co  m
public final void requestBoardLayout(GoogleApiClient apiClient) {
    try {
        Log.d(TAG, "requestBoardLayout");
        JSONObject payload = new JSONObject();
        payload.put(KEY_COMMAND, KEY_BOARD_LAYOUT_REQUEST);
        sendMessage(apiClient, payload.toString());
    } catch (JSONException e) {
        Log.e(TAG, "Cannot create object to request board layout", e);
    }
}

From source file:com.graphhopper.http.GraphHopperServlet.java

private void writeJson(HttpServletRequest req, HttpServletResponse res, GHResponse rsp, float took)
        throws JSONException, IOException {
    boolean enableInstructions = getBooleanParam(req, "instructions", true);
    boolean pointsEncoded = getBooleanParam(req, "points_encoded", true);
    boolean calcPoints = getBooleanParam(req, "calc_points", true);
    boolean includeElevation = getBooleanParam(req, "elevation", false);
    JSONObject json = new JSONObject();
    JSONObject jsonInfo = new JSONObject();
    json.put("info", jsonInfo);

    if (rsp.hasErrors()) {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        for (Throwable t : rsp.getErrors()) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("message", t.getMessage());
            map.put("details", t.getClass().getName());
            list.add(map);/*from   w  w  w  .  j  a  v a 2 s.c  om*/
        }
        jsonInfo.put("errors", list);
    } else if (!rsp.isFound()) {
        Map<String, String> map = new HashMap<String, String>();
        map.put("message", "Not found");
        map.put("details", "");
        jsonInfo.put("errors", Collections.singletonList(map));
    } else {
        jsonInfo.put("took", Math.round(took * 1000));
        JSONObject jsonPath = new JSONObject();
        jsonPath.put("distance", Helper.round(rsp.getDistance(), 3));
        jsonPath.put("time", rsp.getMillis());

        if (calcPoints) {
            jsonPath.put("points_encoded", pointsEncoded);

            PointList points = rsp.getPoints();
            if (points.getSize() >= 2)
                jsonPath.put("bbox", rsp.calcRouteBBox(hopper.getGraph().getBounds()).toGeoJson());

            jsonPath.put("points", createPoints(points, pointsEncoded, includeElevation));

            if (enableInstructions) {
                InstructionList instructions = rsp.getInstructions();
                jsonPath.put("instructions", instructions.createJson());
            }
        }
        json.put("paths", Collections.singletonList(jsonPath));
    }

    writeJson(req, res, json);
}