I have a JSON:
{
"Bills": {
"name": "Mr.X",
"creditCardNumber": "1234567890",
"billDetails": [{
"PaymentDueDate": "07-03-2018",
"StatementDate": "24-02-2018",
"AmountDue": "2156"
},
{
"PaymentDueDate": "05-02-2018",
"StatementDate": "23-01-2018",
"AmountDue": "3256"
},
{
"PaymentDueDate": "07-01-2018",
"StatementDate": "24-12-2017",
"AmountDue": "1132"
},
{
"PaymentDueDate": "07-12-2017",
"StatementDate": "24-10-2017",
"AmountDue": "7654"
}
]
}
}
I am trying to read the JSON object but getting null for JSONArray i.e. billDetailsArr
public static void readJSONFile() throws java.text.ParseException {
JSONParser parser = new JSONParser();
JSONObject data;
try {
data = (JSONObject) parser.parse(new FileReader("\\Bills.json"));
JSONArray billdetailsArr = (JSONArray) data.get("billDetails");
for(int i=0;i<data.size();i++)
{
JSONObject jsonobj_2 = (JSONObject) billdetailsArr.get(i);
String dateStr = (String) jsonobj_2.get(new Date("StatementDate"));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date StatementDate = sdf.parse(dateStr);
}
}
My POJO class is:
public class BillDetails {
private Date PaymentDueDate;
private Date StatementDate;
private String AmountDue;
}
I want to have StatementDate & PaymentDueDate in date format not as String. Is my code correct?