So I've queried a server and now I want to parse it into a java object this is what my JSON line looks like: { "_id" : { "$oid" : "547084b10ede9afb9ef5fa40"} , "UUID" : "INSERT UUID HERE" , "rank" : "Owner" , "coins" : 10 , "friends" : [ "UUID" , "UUID"]} but I want to convert it into String s = The UUID; String r = the rank; Integer c = coins; ArrayList<String> friends = ArrayList<String>(); and then get all the friends and put them to the arraylist. So what I'm asking how to get parts of the line into a java line
Assist Yes of course. What I googled "Parse JSON to Java object". but I don't really understand/know how to do it. This is the first time I start learning JSON I've even looked how the UUID fetcher worked but then I've got this error java.lang.ClassCastException: org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray
Funergy Doesn't this page give a quite clear explanation (with examples?). I'd suggest you to use a page like http://jsbeautifier.org/ to make the JSON more readable.
Assist I've already seen that one but JSONObject obj =newJSONObject(" .... "); Doesn't let me use the "....." It says JSONObject obj =newJSONObject(" .... "); needs to be like this JSONObject obj =newJSONObject();
Funergy I don't know which one Craftbukkit is using, but they should all work pretty much the same. Give me a moment, I'll take a look. Edit: I don't think Craftbukkit is even using any special JSON library. You're probably talking about the default json library org.json.simple. You should download the library I linked earlier.
Assist Where is the download link? I can't find it and if I downloaded it then, do I need to use MANIFEST.MF to use it again?
You need to use the json parser: Code: String jsonString; JSONParser parser = new JSONParser(); JSONObject object = (JSONObject) parser.parse(jsonString); And you do not need to include the library because it's already included in the bukkit api.
Cybermaxke TY. but I have an array in the JSON line how should I put them into a HashSet/ArrayList ["Funergy","DubstepPrins"] nvm Solved EDIT by Moderator: merged posts, please use the edit button instead of double posting.