I'd like to firstly apologize for my use of terminologies as I am fairly new to working with Json objects and arrays.
I have searched for various examples where I can extract data from a Json object, but none are similar to the situation I am in. I am attempting to extract the string "Plan A (Economy Plan)", "Plan B (Deluxe Plan)", and "Plan C (Ramadan)" from the following Json:
{
"status": "success",
"data": {
"1:Plan A (Economy Plan)": [{
"idscheme": "49",
"plan_name": "1",
"plan_id": "ABS-772",
"term": "8",
"payment": "1000",
"amount": "8000",
"expected_amount": null,
"added_by": "2",
"updated_on": "2017-09-27"
}, {
"idscheme": "50",
"plan_name": "1",
"plan_id": "ABS-773",
"term": "8",
"payment": "2000",
"amount": "16000",
"expected_amount": null,
"added_by": "1",
"updated_on": "2017-09-28"
}, {
"idscheme": "48",
"plan_name": "1",
"plan_id": "ABS-762",
"term": "7",
"payment": "4000",
"amount": "28000",
"expected_amount": null,
"added_by": "1",
"updated_on": "2017-09-28"
}],
"2:Plan B (Deluxe Plan)": [{
"idscheme": "33",
"plan_name": "2",
"plan_id": "ABS-486",
"term": "8",
"payment": "2000",
"amount": "16000",
"expected_amount": null,
"added_by": "2",
"updated_on": "2017-09-27"
}, {
"idscheme": "47",
"plan_name": "2",
"plan_id": "ABS-831",
"term": "7",
"payment": "3000",
"amount": "21000",
"expected_amount": null,
"added_by": "2",
"updated_on": "2017-09-27"
}, {
"idscheme": "46",
"plan_name": "2",
"plan_id": "ABS-776",
"term": "7",
"payment": "4000",
"amount": "28000",
"expected_amount": null,
"added_by": "2",
"updated_on": "2017-09-27"
}],
"5:Plan C (Ramadan)": [{
"idscheme": "51",
"plan_name": "5",
"plan_id": "ABS-865",
"term": "7",
"payment": "3000",
"amount": "21000",
"expected_amount": null,
"added_by": "42",
"updated_on": "2017-10-15"
}, {
"idscheme": "52",
"plan_name": "5",
"plan_id": "ABS-389",
"term": "8",
"payment": "4000",
"amount": "32000",
"expected_amount": null,
"added_by": "42",
"updated_on": "2017-10-15"
}, {
"idscheme": "53",
"plan_name": "5",
"plan_id": "ABS-451",
"term": "8",
"payment": "5000",
"amount": "40000",
"expected_amount": null,
"added_by": "42",
"updated_on": "2017-10-15"
}]
},
"plancount": 3
}
The idea is that this Json object is created from the use of an API, and I want to dynamically put the different "plans" in a spinner in Android. Currently I have hard-coded the values into the spinner, but that number of plans can change and I don't want to hard-code it each time.
The format of the Json object is a little different than usual since the API's were built in such a way, is there a way to extract the different plans instead of having to change the API since that would require some more work?
Below are the steps I have followed to achieve this:
- String APIUrl = "url for API"
- I am sending the APIUrl along with the necessary data to a class DataAPI which extends AsyncTask and sends an Http POST request.
- The server response in stored in a String JsonResult.
- I have then created a jsonObject from the string and checked for whether
jsonObject.getString("status").equals("success")
- It is here that I am getting stuck because I don't know if there is a way to extract the required strings ("1:Plan A (Economy Plan)", "2:Plan B (Deluxe Plan)", and "3:Plan C (Ramadan)") so I can split ("Plan A (Economy Plan)", "Plan B (Deluxe Plan)", and "Plan C (Ramadan)") and place into the Android spinner.
Thanks you very much for your help, and if you'd like any changes or things I need to include in the post, please let me know.