You have a JSONArray containing two JSONObject children.
The first JSONObject has the following fields:
- _id
- task_name
- task_day
- task_priority
- task_description
- task_goal
- user
The second JSONObject has the following fields:
Since your first JSONObject doesn't not contain the task_goalid field, you won't be able to retrieve it from that object. If the field is optional, which it appears to be, you can either check if the field exists first before trying to get it using JSONObject.has("task_goalid") or get it as an optional string using JSONObject.optString("task_goalid", "No Value").
Using JSONObject.has() is the safer option here since you can definitively say whether that field exists or not. Using JSONObject.optString() allows you to assign a default value to missing fields more easily. Either method will work so it's up to you which one better suits your needs.