Introduction
Nowadays, JSON web services are preferred instead of XML web services. So in most of the mobile applications, you just need to parse JSON and show on the mobile screen.
So we have to write Java classes to parse the response JSON and convert it to the business objects (Java class with setters and getters).
But now, you don't need to write a line of code to parse the JSON. There is an JSON parser tool available which will create all required Java classes for you. So you can parse complex JSON within few seconds. Although it is very simple to use, I will explain the steps below.
How to Use
Here are the steps to use this online tool:
- Following is the JSON string that needs to be parsed. It is returning a list of students.
- Sometimes, there are some JSON keys with
null
values. For example, the above JSON rollNumber key. So you must assign a custom value to this key. Let us assign it 10.
- If there are some blank JSON Arrays in JSON, they add at least one value. For example, if "students":[] then you should add one student json object it in.
- It is recommended that you keep only one object in JSON Array type objects. It will speed up the tool and also you don't need to search for
null
and blank JSON arrays in the JSON. For example, in the above JSON, we can remove the second object in students
Array:
- Now click JSON Parser Tool ne and fill the form as below:
- Now click submit button and wait for a second server to send you zip file and save it. Extract the zip, all bean classes and parser class in the folder. Copy them into your Android project and enjoy.
Important Points
- If there are JSON Array objects in the JSON string, please make sure those have at least one value in it.
- It is recommended to keep only one object in a JSON array. Although tool will work with any type of JSON, it is for best results.
- Assign a fake value to the keys having
null
value.