Example usage for org.json.simple JSONObject get

List of usage examples for org.json.simple JSONObject get

Introduction

In this page you can find the example usage for org.json.simple JSONObject get.

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:mp3downloader.ZingSearch.java

public static ArrayList<Playlist> searchPlaylist(String term) {
    ArrayList<Playlist> playlists = new ArrayList<>();
    try {//w  w  w . j a  v  a2s .co m
        String content = getSearchResult(term, 8);
        JSONParser parser = new JSONParser();
        JSONObject obj = (JSONObject) parser.parse(content);
        JSONArray items = (JSONArray) obj.get("Data");

        for (int i = 0; i < items.size(); i++) {
            JSONObject item = (JSONObject) items.get(i);
            String id = (String) item.get("ID");
            String title = (String) item.get("Title");
            String artist = (String) item.get("Artist");
            String genre = (String) item.get("Genre");
            String pictureUrl = (String) item.get("PictureURL");
            long totalListen = 0;
            if (item.get("TotalListen") != null) {
                totalListen = (long) item.get("TotalListen");
            }
            Playlist p = new Playlist(id, title, artist, genre, pictureUrl, totalListen);
            playlists.add(p);
        }
    } catch (Exception ex) {
        Logger.getLogger(ZingSearch.class.getName()).log(Level.SEVERE, null, ex);
    }
    return playlists;
}

From source file:com.turt2live.hurtle.uuid.UUIDServiceProvider.java

/**
 * Gets the UUID of a player name.//from   w  ww . j  a va 2  s. c  om
 *
 * @param name the name, cannot be null
 *
 * @return the UUID for the player, or null if not found or for invalid input
 */
public static UUID getUUID(String name) {
    if (name == null)
        return null;
    try {
        URL url = new URL("http://uuid.turt2live.com/uuid/" + name);
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String parsed = "";
        String line;
        while ((line = reader.readLine()) != null)
            parsed += line;
        reader.close();

        Object o = JSONValue.parse(parsed);
        if (o instanceof JSONObject) {
            JSONObject jsonObject = (JSONObject) o;
            o = jsonObject.get("uuid");
            if (o instanceof String) {
                String s = (String) o;
                if (!s.equalsIgnoreCase("unknown")) {
                    return UUID.fromString(insertDashes(s));
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:me.fromgate.messagecommander.PLListener.java

private static String jsonToString(String json) {
    JSONObject jsonObject = (JSONObject) JSONValue.parse(json);
    if (jsonObject == null || json.isEmpty())
        return json;
    JSONArray array = (JSONArray) jsonObject.get("extra");
    if (array == null || array.isEmpty())
        return json;
    return jsonToString(array);
}

From source file:com.baystep.jukeberry.JsonConfiguration.java

public static SourceDescription[] getSourceDescriptionArray(JSONObject obj, String key) {
    ArrayList<SourceDescription> list = new ArrayList<>();
    JSONArray array = (JSONArray) obj.get(key);
    if (array != null) {
        Iterator it = array.iterator();
        while (it.hasNext()) {
            JSONObject element = (JSONObject) it.next();

            SourceDescription sd = new SourceDescription();
            sd.name = element.get("name").toString();
            sd.fqn = element.get("fqn").toString();

            list.add(sd);//  w w  w.  ja v  a2  s .c om
        }
    }
    SourceDescription[] output = new SourceDescription[list.size()];
    list.toArray(output);
    return output;
}

From source file:com.modeln.batam.connector.wrapper.Step.java

public static Step fromJSON(JSONObject obj) {
    Integer order = (Integer) obj.get("order");
    String name = (String) obj.get("name");
    String startDate = (String) obj.get("start_date");
    String endDate = (String) obj.get("end_date");
    String input = (String) obj.get("input");
    String expected = (String) obj.get("expected");
    String output = (String) obj.get("output");
    String status = (String) obj.get("status");
    String error = (String) obj.get("error");
    boolean isCustomFormatEnabled = (Boolean) obj.get("isCustomFormatEnabled") == null ? false
            : (Boolean) obj.get("isCustomFormatEnabled");
    String customFormat = (String) obj.get("customFormat");
    String customEntry = (String) obj.get("customEntry");

    return new Step(order, name, startDate == null ? null : new Date(Long.valueOf(startDate)),
            endDate == null ? null : new Date(Long.valueOf(endDate)), input, expected, output, status, error,
            isCustomFormatEnabled, customFormat, customEntry);
}

From source file:bammerbom.ultimatecore.bukkit.commands.CmdMinecraftservers.java

public static Status getStatus(MinecraftServer service) {
    String status;//from  ww  w. ja va2  s.c  o  m

    try {
        URL url = new URL("http://status.mojang.com/check?service=" + service.getURL());
        BufferedReader input = new BufferedReader(new InputStreamReader(url.openStream()));
        Object object = parser.parse(input);
        JSONObject jsonObject = (JSONObject) object;

        status = (String) jsonObject.get(service.getURL());
    } catch (Exception e) {
        return Status.UNKNOWN;
    }

    return status(status);
}

From source file:com.rmtheis.yandtran.YandexTranslatorAPI.java

private static String[] jsonArrToStringArr(final String inputString, final String propertyName)
        throws Exception {
    final JSONArray jsonArr = (JSONArray) JSONValue.parse(inputString);
    String[] values = new String[jsonArr.size()];

    int i = 0;/* w  ww. jav  a  2  s .  c om*/
    for (Object obj : jsonArr) {
        if (propertyName != null && propertyName.length() != 0) {
            final JSONObject json = (JSONObject) obj;
            if (json.containsKey(propertyName)) {
                values[i] = json.get(propertyName).toString();
            }
        } else {
            values[i] = obj.toString();
        }
        i++;
    }
    return values;
}

From source file:com.turt2live.hurtle.uuid.UUIDServiceProvider.java

/**
 * Gets the name of a player for the specified UUID.
 *
 * @param uuid the uuid to lookup, cannot be null
 *
 * @return the player's name, or null if not found or for invalid input
 *///ww  w  .  j  a v a  2 s. c o  m
public static String getName(UUID uuid) {
    if (uuid == null)
        return null;
    try {
        URL url = new URL("http://uuid.turt2live.com/name/" + uuid.toString().replaceAll("-", ""));
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String parsed = "";
        String line;
        while ((line = reader.readLine()) != null)
            parsed += line;
        reader.close();

        Object o = JSONValue.parse(parsed);
        if (o instanceof JSONObject) {
            JSONObject jsonObject = (JSONObject) o;
            Object status = jsonObject.get("status");
            if (status instanceof String && ((String) status).equalsIgnoreCase("ok")) {
                o = jsonObject.get("name");
                if (o instanceof String) {
                    return (String) o;
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.modeln.batam.connector.wrapper.ReportEntry.java

@SuppressWarnings("unchecked")
public static ReportEntry fromJSON(JSONObject obj) {
    String id = (String) obj.get("id");
    String name = (String) obj.get("name");
    String buildId = (String) obj.get("build_id");
    String buildName = (String) obj.get("build_name");
    String description = (String) obj.get("description");
    String startDate = (String) obj.get("start_date");
    String endDate = (String) obj.get("end_date");
    String status = (String) obj.get("status");

    List<String> logs = new ArrayList<String>();
    JSONArray logsArray = (JSONArray) obj.get("logs");
    if (logsArray != null) {
        for (Iterator<String> it = logsArray.iterator(); it.hasNext();) {
            String log = (String) it.next();
            logs.add(log);/*from   w w  w  . j a v a  2s . c  om*/
        }
    }
    boolean isCustomFormatEnabled = (Boolean) obj.get("isCustomFormatEnabled") == null ? false
            : (Boolean) obj.get("isCustomFormatEnabled");
    String customFormat = (String) obj.get("customFormat");
    String customEntry = (String) obj.get("customEntry");
    return new ReportEntry(id, name, buildId, buildName, description,
            startDate == null ? null : new Date(Long.valueOf(startDate)),
            endDate == null ? null : new Date(Long.valueOf(endDate)), status, logs, isCustomFormatEnabled,
            customFormat, customEntry);
}

From source file:Controller.MainClass.java

public static String getLocationFromAPi(String CityName) throws ParseException {
    String[] list;/*from w ww.  ja  v  a  2 s.c  om*/
    list = CityName.replaceAll("[^a-zA-Z]", "").toLowerCase().split("\\s+");
    CityName = list[0];
    String Address = "";
    String url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + CityName + "&sensor=false";

    try {
        String genreJson = IOUtils.toString(new URL(url));
        JSONObject genreJsonObject = (JSONObject) JSONValue.parseWithException(genreJson);
        JSONArray genreArray = (JSONArray) genreJsonObject.get("results");
        if (genreArray.size() == 0) {
            return "";
        } else {
            JSONObject firstGenre = (JSONObject) genreArray.get(0);
            String City = firstGenre.get("formatted_address").toString();
            JSONObject obj = (JSONObject) firstGenre.get("geometry");
            JSONObject loc = (JSONObject) obj.get("location");
            String lat = loc.get("lat").toString();
            String lng = loc.get("lng").toString();
            Address = (String) (lat + "/" + lng + "/" + City);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return Address;
}