Answer the question
In order to leave comments, you need to log in
Why is this java shit code?
Initial JSON
{"data":[{"permission":"publish_actions","status":"granted"}]}
String status = "";
try {
JSONObject result = response.getJSONObject();
status = ((JSONObject) ((JSONArray) result.get("data")).get(0)).getString("status");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println(status);
Answer the question
In order to leave comments, you need to log in
status = ((JSONObject) ((JSONArray) result.get("data")).get(0)).getString("status");
At least NullPointerException is likely to be caught if, for example, the array in JSON is empty. The same is true for the parameters - there is no check for their presence. In general, I advise you to use Gson for such purposes. Life will be much easier
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question