Skip to content

Instantly share code, notes, and snippets.

@clucle
Created May 24, 2017 04:23
Show Gist options
  • Save clucle/940636bdad2d18fbbc0d9da230d57e76 to your computer and use it in GitHub Desktop.
Save clucle/940636bdad2d18fbbc0d9da230d57e76 to your computer and use it in GitHub Desktop.
JSON Array Parsing
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
public class Main {
public static void main(String[] args) {
String str = "[{'json_type_1'},{'json_type_2'},{'json_type_3'}]"
JSONParser parser = new JSONParser();
JSONArray jsonArray = new JSONArray();
try {
jsonArray = (JSONArray) parser.parse(str);
} catch (Exception e) {
System.out.println(e.toString());
}
for (int indexJson = 0; indexJson < jsonArray.size(); indexJson++) {
JSONObject obj = (JSONObject) jsonArray.get(indexJson);
System.out.println(obj.get("endTime").toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment