UPDATE 1/9/2018
Several years have passed since this (now popular) question was asked. Although I still agree that there was a need for json-simple at the time, I think the SO community is better served by having a checkmark next to Jackson's solution. I do not accept my answer today; Jackson is very good!
I think this decent json simple library is a victim of poor documentation. If you are not using JSONParser (see the picture!), But instead use this JSONValue.parse () method, it will all look like this:
//JSONParser parser = new JSONParser(); // DON'T USE THIS Object obj = JSONValue.parse("A JSON string - array of objects: [{},{}] - goes here"); JSONArray arrFilings = (JSONArray)obj; System.out.println("We can print one this way..."); System.out.println(arrFilings.get(5) + "\n"); System.out.println("We can enumerate the whole array..."); for(Object objFiling : arrFilings){ System.out.println(objFiling); } System.out.println("\n"); System.out.println("We can access object properties this way..."); for(Object objFiling : arrFilings){ JSONObject o = (JSONObject)objFiling; // MUST cast to access .get() MyJSObject.fyq = o.get("fyq"); } System.out.println("\n");
Thanks to everyone who posted. The json-simple question was a question, and this is the only json-simple answer to date. Jackson REALLY looks smooth, and Amazon uses it in the SDK for Java too, sooo .... if its good enough for AWS ....
source share