Interface Json


public interface Json
A helper class that allows converting JavaScript objects into a JSON string and creating JavaScript objects from a JSON string.

When the web page is unloaded, all the JavaScript objects will be automatically disposed. Access to the already disposed JavaScript object will lead to the IllegalStateException.

  • Method Summary

    Modifier and Type
    Method
    Description
    <T> T
    parse(String json)
    Creates an object that represents the result of parsing the given string in JSON format.
    stringify(JsObject jsObject)
    Converts the given JavaScript object into a JSON string.
  • Method Details

    • parse

      @Nullable <T> T parse(String json)
      Creates an object that represents the result of parsing the given string in JSON format.
      Type Parameters:
      T - one of the following types: java.lang.Boolean, java.lang.Double, java.lang.String, or JsObject
      Parameters:
      json - a string in JSON format
      Returns:
      the result of parsing. Can be null if the result of parsing is null. For example, when the given JSON string is "null", then the method returns null
      Throws:
      JsException - when an invalid JSON string is passed
      IllegalArgumentException - when json is empty or blank
    • stringify

      String stringify(JsObject jsObject)
      Converts the given JavaScript object into a JSON string.
      Parameters:
      jsObject - a JavaScript object to convert into a JSON string
      Returns:
      a JSON representation of the given JavaScript object
      Throws:
      JsException - when the given JavaScript object cannot be converted to a JSON string. For example, when a circular reference is found in the given JavaScript object