Package JsonFse

Class JsonObj


  • public class JsonObj
    extends java.lang.Object
    Represents a JSON object. It holds the root node of a JSON tree, allows traversing through the pairs in the tree and accessing individual pairs.
    Author:
    Friedemann Seebass
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected NodeObj mNodeObj
      The root node of the JSON tree.
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonObj()
      Creates an empty JSON object to be filled later by adding pairs.
      JsonObj​(java.lang.String str)
      Parses the given string into a recursive JSON tree.
      JsonObj​(NodeObj no)
      Creates a JSON object and sets its root object to the parameter.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addPair​(java.lang.String string)
      Adds a new pair where the value is null to the end of the node's member list.
      void addPair​(java.lang.String string, boolean value)
      Adds a new pair where the value is a boolean to the end of the node's member list.
      void addPair​(java.lang.String string, double value)
      Adds a new pair where the value is a number to the end of the node's member list.
      void addPair​(java.lang.String string, int value)
      Adds a new pair where the value is an integer number to the end of the node's member list.
      void addPair​(java.lang.String string, java.lang.String value)
      Adds a new pair where the value is a string to the end of the node's member list.
      void addPair​(java.lang.String string, JsonObj value)
      Adds a new pair where the value is another JsonObj to the end of the node's member list.
      void addPair​(java.lang.String string, NodeArray value)
      Adds a new pair where the value is a NodeArray to the end of the node's member list.
      NodePair get​(int idx)
      Gets the pair with index idx of the JSON object.
      java.lang.String getAsString()
      Returns the JSON tree as formatted string.
      NodePair getNext()
      Gets the next pair in the JSON object.
      NodeObj getNodeObj()
      Returns the root node of the JSON tree.
      NodeValue getValue​(java.lang.String string)
      Gets the value of the pair with the string (i. e. the label) given in the parameter.
      java.lang.String getValueAsString​(java.lang.String string)
      Gets the value of the pair with the string (i. e. the label) given in the parameter and converts it to a string.
      static void main​(java.lang.String[] args)  
      void setNodeObj​(NodeObj no)
      Sets the root node of the JSON tree.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • mNodeObj

        protected NodeObj mNodeObj
        The root node of the JSON tree.
    • Constructor Detail

      • JsonObj

        public JsonObj()
        Creates an empty JSON object to be filled later by adding pairs.
      • JsonObj

        public JsonObj​(NodeObj no)
        Creates a JSON object and sets its root object to the parameter.
        Parameters:
        no - The root node object of the new JSON object.
      • JsonObj

        public JsonObj​(java.lang.String str)
                throws ParseErrorEx
        Parses the given string into a recursive JSON tree.
        Parameters:
        str - the JSON object to parse as String
        Throws:
        ParseErrorEx - Is thrown if the parser detects an error in the string.
    • Method Detail

      • getNodeObj

        public NodeObj getNodeObj()
        Returns the root node of the JSON tree.
        Returns:
        The root node.
      • setNodeObj

        public void setNodeObj​(NodeObj no)
        Sets the root node of the JSON tree.
        Parameters:
        no - The node object to be set.
      • getAsString

        public java.lang.String getAsString()
        Returns the JSON tree as formatted string.
        Returns:
        The whole JSON object as formatted string.
      • getNext

        public NodePair getNext()
        Gets the next pair in the JSON object.
        Returns:
        The next pair in the JSON object.
      • get

        public NodePair get​(int idx)
        Gets the pair with index idx of the JSON object.
        Parameters:
        idx - index of the pair to retrieve
        Returns:
        The pair with index idx or null if index out of range.
      • getValueAsString

        public java.lang.String getValueAsString​(java.lang.String string)
        Gets the value of the pair with the string (i. e. the label) given in the parameter and converts it to a string. The search starts at index 0, and only the first pair is found if there should be more than one with the same label.
        Parameters:
        string - The label to search.
        Returns:
        The value of the label as a string or null if not found.
      • getValue

        public NodeValue getValue​(java.lang.String string)
        Gets the value of the pair with the string (i. e. the label) given in the parameter. The search starts at index 0, and only the first pair is found if there should be more than one with the same label.
        Parameters:
        string - The label to search.
        Returns:
        The value of the label or null if not found.
      • addPair

        public void addPair​(java.lang.String string,
                            java.lang.String value)
        Adds a new pair where the value is a string to the end of the node's member list.
        Parameters:
        string - The pair's label.
        value - The pair's value.
      • addPair

        public void addPair​(java.lang.String string,
                            int value)
        Adds a new pair where the value is an integer number to the end of the node's member list.
        Parameters:
        string - The pair's label.
        value - The pair's value.
      • addPair

        public void addPair​(java.lang.String string,
                            double value)
        Adds a new pair where the value is a number to the end of the node's member list.
        Parameters:
        string - The pair's label.
        value - The pair's value.
      • addPair

        public void addPair​(java.lang.String string,
                            boolean value)
        Adds a new pair where the value is a boolean to the end of the node's member list.
        Parameters:
        string - The pair's label.
        value - The pair's value.
      • addPair

        public void addPair​(java.lang.String string)
        Adds a new pair where the value is null to the end of the node's member list.
        Parameters:
        string - The pair's label.
      • addPair

        public void addPair​(java.lang.String string,
                            NodeArray value)
        Adds a new pair where the value is a NodeArray to the end of the node's member list.
        Parameters:
        string - The pair's label.
        value - The pair's value.
      • addPair

        public void addPair​(java.lang.String string,
                            JsonObj value)
        Adds a new pair where the value is another JsonObj to the end of the node's member list.
        Parameters:
        string - The pair's label.
        value - The pair's value.
      • main

        public static void main​(java.lang.String[] args)