dreameo Posted September 18, 2018 Share Posted September 18, 2018 (edited) Seems like other snippets of getting item data didn't work so I just made one myself. Who knows how long this might last. If you're interested in storing values you wish to lookup instead of having to parse the json data stored, please implement it yourself (hashmap). I left it out on purpose. How it works: Spoiler 1. Splits each JSON item into a 'block' (array of strings) 2. Gets each property from the block (property:value) 3. returns the value if it matches the property + name of item Usage: Spoiler All look-ups return an Optional<String>. Be sure to convert to numeric if that's what you're after. ItemLookup.get("Trout", Property.SELL_AVERAGE); // case sensitive Code: Spoiler import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.Arrays; import java.util.Optional; import java.util.regex.Pattern; public class ItemLookup { private static String json; private ItemLookup(){ } private static void initData(){ try { URL url = new URL("https://rsbuddy.com/exchange/summary.json"); URLConnection connect = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(connect.getInputStream())); json = in.readLine(); in.close(); } catch (IOException e) { e.printStackTrace(); } } public static Optional<String> get(String itemName, Property property){ if(json == null) { initData(); } Optional<String> itemBlock = Arrays .stream(json.split("\\{")) .filter(phrase -> findString(itemName, phrase)) .findFirst(); if(itemBlock.isPresent()) { return Arrays .stream(itemBlock.get().split(",")) .filter(phrase -> findString(property.getProperty(), phrase)) .map(ItemLookup::clean) .findFirst(); } else { return Optional.empty(); } } private static boolean findString(String target, String phrase){ return phrase.matches(".*\"" + Pattern.quote(target) + "\".*"); } private static String clean(String value){ value = value.split(":")[1]; return value.replaceAll("}","").replaceAll("\"",""); } } Spoiler public enum Property { ID("id"), NAME("name"), MEMBERS("members"), SP("sp"), BUY_AVERAGE("buy_average"), BUY_QUANTITY("buy_quantity"), SELL_AVERAGE("sell_average"), SELL_QUANTITY("sell_quantity"), OVERALL_AVERAGE("overall_average"), OVERALL_QUANTITY("overall_quantity"); private String property; Property(String property){ this.property = property; } public String getProperty() { return property; } } Edited August 18, 2019 by dreameo 4 3 Quote Link to comment Share on other sites More sharing options...
Eagle Scripts Posted September 18, 2018 Share Posted September 18, 2018 Thanks for the contribution . Quote Link to comment Share on other sites More sharing options...
NoFloob Posted March 10, 2019 Share Posted March 10, 2019 Thank you!!!!!!!!!!!!!!! 1 Quote Link to comment Share on other sites More sharing options...
redeems Posted March 15, 2019 Share Posted March 15, 2019 Just because I know people will have issues converting this. This is how you do that. String Itemname = "Logs"; Optional<String> Itemprice = ItemLookup.get(Itemname, Property.SELL_AVERAGE); int ItemPriceConverted = Integer.valueOf(Itemprice.get()); log(Itemname + " are worth " + ItemPriceConverted + " gp"); Great stuff dreameo 1 Quote Link to comment Share on other sites More sharing options...