Class JsonUtils

java.lang.Object
org.schabi.newpipe.extractor.utils.JsonUtils

public final class JsonUtils extends Object
  • Method Details

    • getValue

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

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

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

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

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

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

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

      public static com.grack.nanojson.JsonArray toJsonArray(String responseBody) throws ParsingException
      Throws:
      ParsingException
    • toJsonObject

      public static com.grack.nanojson.JsonObject toJsonObject(String responseBody) throws ParsingException
      Throws:
      ParsingException
    • getJsonData

      public static com.grack.nanojson.JsonObject getJsonData(String html, String variable) throws com.grack.nanojson.JsonParserException, 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
      ArrayIndexOutOfBoundsException
    • getStringListFromJsonArray

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