Code example for JSONObject: Parsing JSON documents

Methods: getIntgetJSONObjecthasoptJSONObject

0
  private final NodeId node;
  private final NodeId parent;
 
  public NodeEvent(JSONObject message) throws JSONException {
    super(message);
    JSONObject params = message.optJSONObject("params");
    if (params == null) {
      log.severe("Cannot parse " + message);
    } 
    int parentNodeId = params.getInt("parentNodeId");
 
    if (params.has("node")) {
      params = params.getJSONObject("node");
    } 
    int nodeId = params.getInt("nodeId");
 
    this.node = new NodeId(nodeId);
    this.parent = new NodeId(parentNodeId);
 
  }