Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • how to use json minimal


    kamilo
     Share

    Recommended Posts

    https://eclipsesource.com/blogs/2013/04/18/minimal-json-parser-for-java/

    need to use it to grab the GE data, anyone know how to use this. All i see it github files? do i just import that in my project or eclipse. i've never done osmetihng like this please help

    private final static String RSBUDDY_URL = "https://rsbuddy.com/exchange/summary.json";
    
    public static HashMap<String, Integer> getPriceMap(List<String> items) {
    		HashMap<String, Integer> priceMap = new HashMap<>();
    
    		try {
    			URL url = new URL(RSBUDDY_URL);
    			BufferedReader jsonFile = new BufferedReader(new InputStreamReader(url.openStream()));
    			JsonObject priceJSON = JsonObject.readFrom(jsonFile.readLine());
    			Iterator<Member> iterator = priceJSON.iterator();
    			
    			while (iterator.hasNext()) {
    				JsonObject itemJSON = priceJSON.get(iterator.next().getName()).asObject();
    				String itemName = itemJSON.get("name").asString();
    				if (items.contains(itemName)) {
    					priceMap.put(itemName, itemJSON.get("buy_average").asInt());
    				}
    			}
    		} catch (Exception e) {
    			log("Failed to grab item prices!");
    		}
    		return priceMap;
    	}
    Link to comment
    Share on other sites

    DB3 will have GSON as a dependency. You might want to look into using that if you're writing on DB2 :) 
     

    https://rsbuddy.com/exchange/summary.json has all of the items that RSBuddy has client data on at the moment. Their data is in the form of

    "1234_id" : {
      some_keys : some_vals;
    },

    Which means you'll have to find a way to parse out information where the item ID is the key to the rest of the data for the JSON object.

    Note (edit): I intentionally left out code examples, but the general strategy for parsing out information like this is to get your JSON string, pull it in as a JsonElement, send it to a JsonObject, and then parse what you need using those IDs as keys.

     

    JsonElement e = JsonParser.parseString(json);
    JsonObject o = e.getAsJsonObject();
    
    ...
      
    /*
    You now have a JsonObject with all of the data. Pull it apart how you wish
    "2" : {
    ...
    },
    "5" : {
    ...
    },
    etc
    */

     

    Edited by Xephy
    Link to comment
    Share on other sites

    15 minutes ago, Xephy said:

    DB3 will have GSON as a dependency. You might want to look into using that if you're writing on DB2 :) 
     

    https://rsbuddy.com/exchange/summary.json has all of the items that RSBuddy has client data on at the moment. Their data is in the form of

    "1234_id" : {
      some_keys : some_vals;
    },

    Which means you'll have to find a way to parse out information where the item ID is the key to the rest of the data for the JSON object.

    Note (edit): I intentionally left out code examples, but the general strategy for parsing out information like this is to get your JSON string, pull it in as a JsonElement, send it to a JsonObject, and then parse what you need using those IDs as keys.

     

    JsonElement e = JsonParser.parseString(json);
    JsonObject o = e.getAsJsonObject();
    
    ...
      
    /*
    You now have a JsonObject with all of the data. Pull it apart how you wish
    "2" : {
    ...
    },
    "5" : {
    ...
    },
    etc
    */

     

    Quality content seal of approval

    Link to comment
    Share on other sites

    17 hours ago, Xephy said:

    DB3 will have GSON as a dependency. You might want to look into using that if you're writing on DB2 :) 
     

    https://rsbuddy.com/exchange/summary.json has all of the items that RSBuddy has client data on at the moment. Their data is in the form of

    "1234_id" : {
      some_keys : some_vals;
    },

    Which means you'll have to find a way to parse out information where the item ID is the key to the rest of the data for the JSON object.

    Note (edit): I intentionally left out code examples, but the general strategy for parsing out information like this is to get your JSON string, pull it in as a JsonElement, send it to a JsonObject, and then parse what you need using those IDs as keys.

     

    JsonElement e = JsonParser.parseString(json);
    JsonObject o = e.getAsJsonObject();
    
    ...
      
    /*
    You now have a JsonObject with all of the data. Pull it apart how you wish
    "2" : {
    ...
    },
    "5" : {
    ...
    },
    etc
    */

     

    17 hours ago, yeeter01 said:

    Quality content seal of approval

    JsonObject cannot be resolved to a type

    i feel dumb for asking these but which libraries or whatever do u have to import and how in order to use those objects?

    Link to comment
    Share on other sites

    12 minutes ago, kamilo said:

    JsonObject cannot be resolved to a type

    i feel dumb for asking these but which libraries or whatever do u have to import and how in order to use those objects?

    @Kamilo i believe JsonObject is only available in DB3, its not currently in DB2 so you would have to import it though a package manager like maven

    Link to comment
    Share on other sites

    14 hours ago, TheCloakdOne said:

    @Kamilo i believe JsonObject is only available in DB3, its not currently in DB2 so you would have to import it though a package manager like maven

    yess i've heard of that, any newbie instructions for me cuz i've never used maven or even know what that is 

    just heard of it

    Link to comment
    Share on other sites

    • 4 weeks later...
    On 8/4/2020 at 6:42 PM, kamilo said:

    yess i've heard of that, any newbie instructions for me cuz i've never used maven or even know what that is 

    just heard of it

    Just now seeing this. Google "gson jar file" and you shouldn't have to use maven. Maven is a big step for beginners, so I'd recommend just using the jar file.

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.