Class JSONObject

  • Direct Known Subclasses:
    JSON, JSONList

    public abstract class JSONObject
    extends Object
    Represents a JSON object. It represents JSON or JSONList.
    • Constructor Detail

      • JSONObject

        public JSONObject()
    • Method Detail

      • parse

        @NotNull
        @Contract("_ -> new")
        public static JSONObject parse​(String json)
        Parse the given string into a JSON object.
        Parameters:
        json - the string to parse
        Returns:
        the JSON object
      • get

        public <T> T get​(int index)
        Get the value at the given index

        Note: this is for JSONList only.

        Type Parameters:
        T - the type of the value
        Parameters:
        index - the index of the value
        Returns:
        the value at the given index
      • get

        public <T> T get​(String key)
        Get the value of the key-value pair

        Note: this is for JSON only.

        Type Parameters:
        T - the type of the value
        Parameters:
        key - the key
        Returns:
        the value
      • getList

        public JSONObject getList​(int index)
        Get the list at the given index

        Note: this is for JSONList only.

        Parameters:
        index - the index of the list
        Returns:
        the list at the given index
      • getList

        public JSONObject getList​(String key)
        Get the list named key

        Note: this is for JSON only.

        Parameters:
        key - the key of the list
        Returns:
        a list named key
      • getJSON

        public JSONObject getJSON​(int index)
        Get as JSON at the given index

        Note: this is for JSONList only.

        Parameters:
        index - the index of the JSON
        Returns:
        the JSON at the given index
      • toJson

        public abstract String toJson()
        Translate this JSON instance into json String
        Returns:
        json String translated from this JSON instance