I am trying to get all the data coming from a API service, but I am having problems accessing the different "levels" inside the JSON response.
I believe my main problem comes when the inner levels include []
I am showing here a reduced part of the JSON response (the entire response is huge). But this part represent clearly my issue
{
“CustomerList”:{
“CustomerType”:”residential”,
“maxAllowed”:”256”,
"serverdate":"2017-05-02",
“Purchases”:[
{
“Car”:[
{
“customerName”:”Fredrik”,
“price”:”25890”,
“currency”:”EUR”,
“Item”:{
“code”:”Audi”,
“model”:”A3”,
“engine”:”diesel”,
“data”:”2017-03-12”,
"$":"\n"
},
"Destination":{
“country”:”Germany”,
“arrivalDate”:”March 25”,
"id":"02201403",
I have been able to access CustomerList
and Purchases
like this
JSONObject customer = (JSONObject) response.get("CustomerList");
JSONArray purchases = customer.getJSONArray("Purchases");
However now I am getting troubles accessing inner fields like Car
, Item
or Destination
and their elements.
The following gives me JSONException
for (int i = 0;i< purchases.length();i++){
JSONObject car = purchases.getJSONObject(i);
String custName = car.getString("customerName");