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
  • JsonReader in script


    Recommended Posts

    I have built an REST API and i want to read from it. My JsonReader class looks like this

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.Reader;
    import java.net.URL;
    import java.nio.charset.Charset;
    import org.json.JSONException;
    import org.json.JSONObject;
    public class JsonReader {
      private static String readAll(Reader rd) throws IOException {
        StringBuilder sb = new StringBuilder();
        int cp;
        while ((cp = rd.read()) != -1) {
          sb.append((char) cp);
        return sb.toString();
      public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
        InputStream is = new URL(url).openStream();
        try {
          BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
          String jsonText = readAll(rd);
          JSONObject json = new JSONObject(jsonText);
          return json;
        } finally {
    	public static  String getTask() {
    	    JSONObject json = null;
    		try {
    			json = readJsonFromUrl("");
    		} catch (JSONException | IOException e) {
    			// TODO Auto-generated catch block
    	    return json.toString();

    this standalone works great, but as soon as i call JsonReader.getTask() in my script 2 tings happens. Either the script doesnt even start when i click start from local scripts / script starts but does nothing, no error in log or anything. did anyone encounter it? Is there any other method how to read from my API?

    Link to comment
    Share on other sites

    Yea i was looking for solution and what i found is basically the same what you said. The libraries arent compiled with script to jar, but i don't know how do i achieve this?

    Link to comment
    Share on other sites

    Maybe i am doing it wrong, but what do you mean by lib foler, i used build path and added external jar. i moved this jar to dreambot where is client.jar, built path again but it didnt help. 
    As i said, idk what you mean by lob folder, maybe i have to decompile that jar and export that package with classes?

    Edit: I also tried exporting it as Runnable jar because it has option to packge all dependant libraries to jar, but that didnt work either, script just doesnt start

    Edited by testymain
    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

    • 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.