Heyyyyy, So I'm trying to use JSON (and failing), so I'd like to know how I can easily get a string from JSON. For example if I get the JSON from: http://status.mojang.com/check, how do I get "minecraft.net"s value easily? I know PHP has a very simply way, so I'm wondering if Java has the same. Any and all help is amazing <3 Thankies
Use a JSON library like @PickNChew suggested, or parse the portion you want yourself with these methods. http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
Thanks I was trying with org.json, but when using JSONObject, I get it must start with "{" which Mojang's status check does not, and then with JSONArray, I get 0 is not a string ;-;
"in" is text from http://status.mojang.com/check - while "s" is "minecraft.net". Code (Java): JSONObject json = new JSONObject(in); String out = json.getString(s); System.out.println(out); Code (Java): JSONArray json = new JSONArray(in); String out = json.getString(s); System.out.println(out); [CODE]
Haha. It's a JSON array you are trying to parse right now. Grab the JSONObject from the array then grab the string.
I literally have no idea anymore ._. Code (Java): JSONArray json = new JSONArray(in); JSONObject jsonO = new JSONObject(json.getString(s)); System.out.println(jsonO.toString()); I tried it and it doesn't work :'( Sorry to be an absolute pain xD I'm guessing it's probably something really simply that I'm just not getting
Code (Text): URL url = new URL("http://status.mojang.com/check"); Scanner scanner = new Scanner(url.openStream()); scanner.close(); JSONArray array = new JSONArray(scanner.next()); JSONObject object = array.getJSONObject(0); String result = object.getString("minecraft.net"); System.out.print(result); You are welcome.