If you are an Android developer, you know that parsing JSON response is not rocket science but if there are lot of elements, coding your JSON Parsing class makes your life literally hell !
Consider this JSON Response from Yahoo as an example
[believe me, I know its painful to look at that crap response !! bear with it for a while ]
Now, what if I ask you to parse this response in 5 mins? You’ll say over my dead body – this is not possible !
But what if I tell you that I can parse this response in around 10 seconds with the tool we have developed – would you be interested in knowing about it ? if so, read further.
@ TheAppGuruz We have done manual JSON parsing for like thousands of times and have wasted valuable time (sigh!) over this brainless thing.
NO MORE !!
[DOWNLOAD JSON PARSING TOOL]
This tool can parse any JSON response in a jiffy – you have to simply follow the 3 Golden Steps
After opening the tool you have downloaded (its an executable jar file – and if you are Java/ Android developer, you know what it is. If you don’t know, google it)
1. Put JSON Parser class in your Android project (you’ll get the code for that class by clicking on ‘Get JSON Parser Class Code’ Button on the tool) – dont change this code if you take my advice (aah…do whatever you want to do – but after monkeying around don’t complain that this damn tool doesn’t work)
2. Put your JSON URL/ JSON Response you want to parse
Note: use ‘post’ method in the same way as ‘get’ method
(this link doesnt work – its just an example)
3. click “Generate Code” button, and Voilà ! You get your JSON parsing class code
Practically, the guide is over here but if you are interested in learning everything visually – follow the guidelines given below
Create an Android Project
Put JSONParser.java class in your Android Project
If you are running this tool for the first and if you dont have the code for JSONParser.java class, you can click on “Get JSON Parser Class Code” button and it will generate the code
Next, You’ll have to copy that code and paste it into your Android Project
This is how your JSONParser.java class should look
Put your JSON Response URL (you can put your JSON Response Text too as other option)
Check this JSON Response from Yahoo I have used in this example
pretty long (and pretty bad too) response
Note: you can use this tool to view formatted JSON response (see the screenshot below).
Generate and Copy Code
Press the Red “Generate Code” Button (if you want to print your parsed response on console – check the “with log” checkbox)
Copy the generated code
I have created a project with an Activity called ‘MainActivity’ – delete the code from this Activity
Change the name of your class from ‘Your Activity’ to ‘Main Activity’ (or whatever your activity name you wan to put)
After you are done with everything, you will see few errors – you have to manage your imports (Ctrl + Shift + O on Windows/ Linux and Command + Shift + O on Mac)
After that to format your code
(Ctrl + Shift + F on Windows/ Linux and Command + Shift + F on Mac)
and you are done !!
Check the final output in screenshot below
This tool saves you hell amount of time (takes less than 10 seconds to generate code) and you wont have to smash your head on wall for those lengthy responses.
If you have any questions or concerns, feel free to put a comment on this post. And if you like this tool, feel free to share it with your friends
Happy Coding !!
[DOWNLOAD JSON PARSING TOOL]
[DOWNLOAD ANDROID PROJECT USED IN THIS EXAMPLE]