How to obtain data from the Json file in the following code

advertisements

I am new to json so please help me to get solve this

propertyAlerts: [
{
    alertDomain: "oiq.core.alert.PropertyAlert",
    alertType: "HERITAGE_DETECTED",
    oiqCreatedDate: "2013-11-04 03:06:26"
}]

By using java, I want to get the following data

OUTPUT:
alertDomain: "oiq.core.alert.PropertyAlert"
alertType: "HERITAGE_DETECTED"
oiqCreatedDate: "2013-11-04 03:06:26"

The following is used by me

public void checklicense(String filename) throws Exception
    {
JSONParser parser=new JSONParser();
Object obj = parser.parse(new FileReader("./output_profiles/"+filename));
JSONObject jsonObject = (JSONObject) obj;
JSONArray jsonMainArr = obj.getJSONArray("propertyalert");
JSONObject childJSONObject = jsonMainArr.getJSONObject(i);
     String alertDomain = childJSONObject.getString("alertDomain");

}

Can any one help me to solve this problem


This tutorial explains the basics of JSON parsing.

I would recommend you to read the entire post as it is something that you will do almost daily in Android development.