1

I'm trying to get the information listed at http://status.mojang.com/check with Java. I understand that it's JSON so I've tried to get that information using varoius examples on the internet but I can't seem to figure out what's wrong.

Here is my code: http://pastebin.com/USYy93kZ

Does anyone know how I can do this?

1 Answer 1

1

- Try using the below method in your class to Parse the JSON.

private static String readAll(BufferedReader rd) throws IOException {
    StringBuilder sb = new StringBuilder();


    String cp = new String();

    while((cp=rd.readLine())!=null){

        sb.append(cp);
    }
    return sb.toString();
  }


public static JSONArray 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);

      JSONArray arr = new JSONArray(jsonText);

      //System.out.println(arr.toString(2));

      return arr;
    } finally {
      is.close();
    }
  }


 public JSONArray go() throws IOException, JSONException {
        JSONArray json = readJsonFromUrl("http://www.comparestructuredproducts.com/AppData.aspx");

        return json;



      }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.