Class JsonUtils


  • public final class JsonUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static com.grack.nanojson.JsonArray getArray​(com.grack.nanojson.JsonObject object, java.lang.String path)  
      static java.lang.Boolean getBoolean​(com.grack.nanojson.JsonObject object, java.lang.String path)  
      static com.grack.nanojson.JsonObject getJsonData​(java.lang.String html, java.lang.String variable)
      Get an attribute of a web page as JSON
      static java.lang.Number getNumber​(com.grack.nanojson.JsonObject object, java.lang.String path)  
      static com.grack.nanojson.JsonObject getObject​(com.grack.nanojson.JsonObject object, java.lang.String path)  
      static java.lang.String getString​(com.grack.nanojson.JsonObject object, java.lang.String path)  
      static java.util.List<java.lang.String> getStringListFromJsonArray​(com.grack.nanojson.JsonArray array)  
      static java.lang.Object getValue​(com.grack.nanojson.JsonObject object, java.lang.String path)  
      static java.util.List<java.lang.Object> getValues​(com.grack.nanojson.JsonArray array, java.lang.String path)  
      static com.grack.nanojson.JsonArray toJsonArray​(java.lang.String responseBody)  
      static com.grack.nanojson.JsonObject toJsonObject​(java.lang.String responseBody)  
      • Methods inherited from class java.lang.Object

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

      • getValue

        @Nonnull
        public static java.lang.Object getValue​(@Nonnull
                                                com.grack.nanojson.JsonObject object,
                                                @Nonnull
                                                java.lang.String path)
                                         throws ParsingException
        Throws:
        ParsingException
      • getString

        @Nonnull
        public static java.lang.String getString​(@Nonnull
                                                 com.grack.nanojson.JsonObject object,
                                                 @Nonnull
                                                 java.lang.String path)
                                          throws ParsingException
        Throws:
        ParsingException
      • getBoolean

        @Nonnull
        public static java.lang.Boolean getBoolean​(@Nonnull
                                                   com.grack.nanojson.JsonObject object,
                                                   @Nonnull
                                                   java.lang.String path)
                                            throws ParsingException
        Throws:
        ParsingException
      • getNumber

        @Nonnull
        public static java.lang.Number getNumber​(@Nonnull
                                                 com.grack.nanojson.JsonObject object,
                                                 @Nonnull
                                                 java.lang.String path)
                                          throws ParsingException
        Throws:
        ParsingException
      • getObject

        @Nonnull
        public static com.grack.nanojson.JsonObject getObject​(@Nonnull
                                                              com.grack.nanojson.JsonObject object,
                                                              @Nonnull
                                                              java.lang.String path)
                                                       throws ParsingException
        Throws:
        ParsingException
      • getArray

        @Nonnull
        public static com.grack.nanojson.JsonArray getArray​(@Nonnull
                                                            com.grack.nanojson.JsonObject object,
                                                            @Nonnull
                                                            java.lang.String path)
                                                     throws ParsingException
        Throws:
        ParsingException
      • getValues

        @Nonnull
        public static java.util.List<java.lang.Object> getValues​(@Nonnull
                                                                 com.grack.nanojson.JsonArray array,
                                                                 @Nonnull
                                                                 java.lang.String path)
                                                          throws ParsingException
        Throws:
        ParsingException
      • getJsonData

        public static com.grack.nanojson.JsonObject getJsonData​(java.lang.String html,
                                                                java.lang.String variable)
                                                         throws com.grack.nanojson.JsonParserException,
                                                                java.lang.ArrayIndexOutOfBoundsException

        Get an attribute of a web page as JSON

        Originally a part of bandcampDirect.

        Example HTML:

         
         <p data-town="{&quot;name&quot;:&quot;Mycenae&quot;,&quot;country&quot;:&quot;Greece&quot;}">
         This is Sparta!</p>
         
         

        Calling this function to get the attribute data-town returns the JsonObject for

         
           {
             "name": "Mycenae",
             "country": "Greece"
           }
         
         
        Parameters:
        html - The HTML where the JSON we're looking for is stored inside a variable inside some JavaScript block
        variable - Name of the variable
        Returns:
        The JsonObject stored in the variable with this name
        Throws:
        com.grack.nanojson.JsonParserException
        java.lang.ArrayIndexOutOfBoundsException
      • getStringListFromJsonArray

        public static java.util.List<java.lang.String> getStringListFromJsonArray​(@Nonnull
                                                                                  com.grack.nanojson.JsonArray array)