Jump to content

Welcome to DreamBot

VIP Enhancement

Want to upgrade your DreamBot experience? Consider signing up for VIP!
VIP allows you to run as many accounts as you want, view the forums ad-free, receive 10% off all script purchases, and so much more!
Visit the store to learn about all of these great features!

Upgrade to VIP Now
Frequently Asked Questions
  • Are you not able to open the client? Make sure you have Java 8 installed
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
Download the DreamBot client today!
Sign in to follow this  

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?

Share this post

Link to post
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

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Create New...