I have long json answer, here it is:
{"head":{},"def":[{"text":"hello","pos":"noun","ts":"?he?l??","tr":[{"text":"привет","pos":"noun","syn":[{"text":"приветствие","pos":"noun","gen":"ср"}],"mean":[{"text":"hi"},{"text":"welcome"}],"ex":[{"text":"big hello","tr":[{"text":"большой привет"}]}]}]},{"text":"hello","pos":"verb","ts":"?he?l??","tr":[{"text":"поздороваться","pos":"verb","asp":"сов","mean":[{"text":"greet"}]}]}]}
As you can see, there are some inner massives and I can't get them out! I could only get "def" key, but I get get, for example, "tr" or "mean".
I found code here, that can be useful for me:
public static void doJson(String link) throws ParseException {
JSONParser parser = new JSONParser();
JSONObject jj = (JSONObject) parser.parse(link);
String died = (String) ((JSONObject) ((JSONObject) jj.get("def")).get("tr")).get("text");
System.out.println(died);
}
But it gives me back an error:
Exception in thread "main" java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject
at StringOfTrans.doJson(StringOfTrans.java:50)
at StringOfTrans.main(StringOfTrans.java:19)
So, I thinkm that's right way, but I need to fix it. How can I do it? I want to work with json-simple and that's my first experience with JSON. So, I've read already how to get objects from JSON if it contains only one array, but I can't find good examples with json-simple for parse inner arrays. Thank you!