Jackson is a good performance rich java library for JSON processing (parsing/generation). more about Jackson at github home page. The Streaming API of Jackson library is the fastest way to parse/generate a JSON. While using JSON there is sometimes a requirement to convert JSON String into a Object. For small string this seems to be a piece of cake, but for long and complex JSON strings things get a bit hairy when using streaming API. Jackson library has a ObjectMapper which does this job very simple but if you like using Streaming API for parsing JSON String following is some piece of code for you:
Following code was compiled using jackson-core-2.2.3.jar which can be downloaded here.
===================JsonStreaming.java============================
===================JsonStreaming.java============================
I haven’t tested the above code for very complex JSON strings but it works for most of them. In the code above parseComplexJSON takes in as parameter JSON string and returns a java.util.Map<String, Object> the Object here can be ArrayList to denote corresponding JSONArray. The code uses a lot of recursion to parse JSON String. All JSONObject are converted to Map<String, Object> and all JSONArray are converted to ArrayList<Object>.
Happy Coding!
http://wiki.fasterxml.com/JacksonStreamingApi [Streaming API of Jackson]
http://wiki.fasterxml.com/JacksonHome
http://wiki.fasterxml.com/JacksonInFiveMinutes [Jackson Overview in 5 minutes]