I have a json data that looks like the following:
It raises an Json exception stating there is "no value for BillCategory". As you can see by the Json data the BillSchedule field is being populated. When I debug the app and put a break point near the variable, the Json data object value is clearly there as well. I have tried assigning a value that doesn't have slashes as a test, with no success. Can someone please help me figure this out, I don't know what I am missing.
I should clarify when I use jsonObject.getString I get "No Value for BillCategory" , when I use jsonObject.optString it returns null even though BillCategory has a value on Json data object
{"bills":[{"BillID":"379","BillName":"Credit Card","Amount":"$700.00","PayType":"Auto","Status":"Not Due","DateDue":"2017-03-15","Title":"DUE!","BillSchedule":"90","BillNote":"Test","BillCategory":"Home Expense\/Utilities\/Gas"}]}
When I do the code below in Android Studio:
JSONObject jsonObject = new JSONObject(result);
jsonArray = jsonObject.getJSONArray("bills");
for (int i = 0; i < jsonArray.length(); i++) {
jsonArray = jsonObject.getJSONArray("bills");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonOBject = jsonArray.getJSONObject(i);
String billID = jsonOBject.getString("BillID");
String billName = jsonOBject.getString("BillName");
String billAmount = jsonOBject.getString("Amount");
String payType = jsonOBject.getString("PayType");
tring billStatus = jsonOBject.getString("Status");
String billDueDate = jsonOBject.getString("DateDue");
String title = jsonOBject.getString("Title");
String billSchedule = jsonObject.getString("BillSchedule");
String billNote = jsonOBject.optString("BillNote");
String category = jsonObject.optString("BillCategory");
BillObject data = new BillObject(billID,billName,billAmount, payType, billStatus,billDueDate, title,billSchedule,billNote,billCategory);
data_list.add(data);
String billID = jsonOBject.getString("BillID");
String billName = jsonOBject.getString("BillName");
String billAmount = jsonOBject.getString("Amount");
String payType = jsonOBject.getString("PayType");
tring billStatus = jsonOBject.getString("Status");
String billDueDate = jsonOBject.getString("DateDue");
String title = jsonOBject.getString("Title");
String billSchedule = jsonObject.getString("BillSchedule");
String billNote = jsonOBject.optString("BillNote");
String category = jsonObject.optString("BillCategory");
BillObject data = new BillObject(billID,billName,billAmount, payType, billStatus,billDueDate, title,billSchedule,billNote,billCategory);
data_list.add(data);
}
It raises an Json exception stating there is "no value for BillCategory". As you can see by the Json data the BillSchedule field is being populated. When I debug the app and put a break point near the variable, the Json data object value is clearly there as well. I have tried assigning a value that doesn't have slashes as a test, with no success. Can someone please help me figure this out, I don't know what I am missing.
I should clarify when I use jsonObject.getString I get "No Value for BillCategory" , when I use jsonObject.optString it returns null even though BillCategory has a value on Json data object
Last edited: