Set json response get_Infographs value in recycler view of this data - android

{
"count": 7,
"next": null,
"previous": null,
"results": [
{
"get_Infographs": [
{
"viewCount": 17,
"likecount": 1,
"unlikeCount": 1,
"shareCount": 0,
"i_id": 532,
"p_id": 532,
"name": "Yoga happiness educational s",
"description": "Yoga happiness educational spiritual journey lifestyle health ",
"c_id": 1,
"status_id": 1,
"source_id": 316,
"date_created": null,
"parentinfograph": "Language english grammar apo",
"internal_url": "http://167.99.86.81:8000/media/DQ532.png",
"external_url": "http://yogadork.com/wp-content/uploads/2015/01/2015-yoga-resolutions-infographic.png",
"mt_id": 3,
"mtcode": "Education",
"topics": [
{
"topic_code": "#EDUCATION"
},
{
"topic_code": "#HEALTH"
}
],
"geoPolitical": [
{
"gp_code": "Default / All GPIDs"
}
],
"entity": [],
"customMetaTags": [
{
"metatag": "#"
}
]
}
]
}
]
}

Read customMetaTags it as ArrayList and then you can pass it using bundle
bundle.putSerializable("some_string", arrayList)

Related

How to get some Specific data from Restapi [flutter]

I want to get only those item which contain type Lunch `` This is a function where I can fetch data from Rest Api and also ApiResponse added
I need to get specific data from a session I send instead of getting the entire array from the response from the Api() method. How do I capture just the only those item which contain type Lunch from the array?
{
"success": true,
"data": [
{
"id": 6,
"name": "Snack",
"type": "breakfast",
"detail": "18",
"image": "uploads/Screenshot_2022-12-04-13-15-13-27.jpg",
"carbs": 6,
"proteins": 4,
"fats": 8,
"cal": 4,
"day": 1,
"created_at": null,
"updated_at": null
},
{
"id": 7,
"name": "Chicken",
"type": "lunch",
"detail": "White Chicken",
"image": "uploads/1670258808164716637219.jpg",
"carbs": 15,
"proteins": 18,
"fats": 10,
"cal": 200,
"day": 1,
"created_at": null,
"updated_at": null
},
{
"id": 8,
"name": "546e57rufjvjv",
"type": "lunch",
"detail": "gdyhj",
"image": "uploads/meat.png",
"carbs": 6578,
"proteins": 2345,
"fats": 5678,
"cal": 4325,
"day": 5,
"created_at": null,
"updated_at": null
},
{
"id": 9,
"name": "Anda Tikki",
"type": "dinner",
"detail": "Egg and Daal",
"image": "uploads/1670259245043112842388.jpg",
"carbs": 10,
"proteins": 8,
"fats": 12,
"cal": 180,
"day": 1,
"created_at": null,
"updated_at": null
},
{
"id": 10,
"name": "Boiled egg and cucumber",
"type": "breakfast",
"detail": "Egg and cucumber",
"image": "uploads/1670259362662817976982.jpg",
"carbs": 10,
"proteins": 5,
"fats": 5,
"cal": 100,
"day": 2,
"created_at": null,
"updated_at": null
}
],
"message": "Food Data retrieved successfully."
}
Future<List<ProductsModel>> getProducts({String? query}) async {
List<ProductsModel> products = [];
var data=[];
try {
String url = 'https://diet.appetitor.app/Celo/api/user/food/2000.0';
var response = await Dio().get(url,
options: Options(headers: {
HttpHeaders.contentTypeHeader: "application/json",
}));
if (response.statusCode == 200) {
products.clear();
ProductsModel.fromJson(response.data);
products.add(ProductsModel.fromJson(response.data));
if (query != null) {
print(products.length);
products = products
.map((e) {
e.data!.where((element) => element.type!.toLowerCase().contains('lunch'));
})
.cast<ProductsModel>()
.toList();
}
}
} on DioError catch (e) {
print(e.response);
}
return products;
}
}
If the response status code returns 200 after making a request with the rest api, assign the data in it to a variable of the type of your model, then you can get it from the variable as you want.

How can I generate a POJO file for this JSON response for auto-deserialization?

I get a JSON response like this from a server:
{
"name_1": [
{
"id": 1,
"type": 1,
"value": "25"
},
{
"id": 2,
"type": 2,
"value": "25"
}
],
"name_2": [
{
"id": 3,
"type": 1,
"value": "25"
},
{
"id": 6,
"type": 4,
"value": "25"
},
{
"id": 7,
"type": 4,
"value": "25"
}
],
"name_3": [
{
"id": 8,
"type": 1,
"value": "25"
}
]
}
How can I generate a POJO file for this in order to use it for auto-deserializing with retrofit?
I tried www.jsonschema2pojo.org, but it wants to create a new class for each JSON object, which is a list (name_1, name_2, name_3), but the count of "name_X" arrays could be different, as well as ther names.
So how can I create a POJO java class for auto-deserializing with GsonConverterFactory in retrofit?
Thanks! :)
You can use Map<String,List<YourObject>> where YourObject contains the id, type and value.
So, response should be :
public class YourObject {
public Map<String, NameDetail> nameDetail;
}
public class NameDetail {
public int id;
public int type;
public String value;
}
And your service with retrofit should return :
Call<YourObject> getStuff();
Your JSON structure is wrong. You should have something like this in order to get list of names:
{
"names" : [
{
"name": "name_1",
"values": [
{
"id": 1,
"type": 1,
"value": "25"
},
{
"id": 2,
"type": 2,
"value": "25"
}
]
},
{
"name": "name_2",
"values": [
{
"id": 3,
"type": 1,
"value": "25"
},
{
"id": 6,
"type": 4,
"value": "25"
},
{
"id": 7,
"type": 4,
"value": "25"
}
]
},
{
"name": "name_3",
"values": [
{
"id": 8,
"type": 1,
"value": "25"
}
]
}
]}
Or if you can't affect server-side then use HashMap<String,List<T>> like Skizo-ozᴉʞS said but it would be the best to change the structure.

How to flatten polymorphic lists with Moshi deserialization

I'm trying to flatten the following Json
[
{
"type": 1,
"field": ""
},
{
"type": 2,
"field": "",
"other_field": ""
},
{
"type": 3,
"field": "",
"list_field": [
{
"type": 4,
"some_field": ""
},
{
"type": 4,
"some_field": ""
}
]
}
]
what I'd like to obtain is the following structure:
[
{
"type": 1,
"field": ""
},
{
"type": 2,
"field": "",
"other_field": ""
},
{
"type": 3,
"field": ""
},
{
"type": 4,
"some_field": ""
},
{
"type": 4,
"some_field": ""
}
]
Since all the items inherit from the same parent class I tried both PolymorphicJsonAdapterFactory and a custom JsonAdapter.Factory but without success.
Is there a way to do that in Moshi?

Json parsing in skyscanner pricing api

I started working with sky-scanner API using volley on Android. I am able to poll the response from the API, however I have no clue how to parse the json which is sent in response, please see json below. The json response is very big, I have never worked with such responses before thus have no idea how can I handle this.
Can someone please help me figure this out? There is no sample implementation done by anyone for skyscanner for android.
JSON response to be parsed to get price, agents, flight number, carrier, duration of flight, image URL of flight.
{
"SessionKey": "97d1_ecilpojl_A",
"Query": {
"Country": "IN",
"Currency": "INR",
"Locale": "en-us",
"Adults": 1,
"Children": 0,
"Infants": 0,
"OriginPlace": "12627",
"DestinationPlace": "11712",
"OutboundDate": "2016-10-09",
"LocationSchema": "Default",
"CabinClass": "Economy",
"GroupPricing": false
},
"Status": "UpdatesComplete",
"Itineraries": [
{
"OutboundLegId": "12627-1610091100-AI-1-11712-1610091515",
"PricingOptions": [
{
"Agents": [
1963108
],
"QuoteAgeInMinutes": 5,
"Price": 19391.08,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fat24%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
2176206
],
"QuoteAgeInMinutes": 5,
"Price": 20190,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fcpin%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
4575202
],
"QuoteAgeInMinutes": 5,
"Price": 20315,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fyatr%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
4056270
],
"QuoteAgeInMinutes": 5,
"Price": 20457.92,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ftpin%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
1943172
],
"QuoteAgeInMinutes": 5,
"Price": 20876,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fakbt%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
3987150
],
"QuoteAgeInMinutes": 5,
"Price": 20888.5,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ft2in%2f1%2f12627.11712.2016-10-09%2fair%2ftrava%2fflights%3fitinerary%3dflight%7c-32672%7c446%7c12627%7c2016-10-09T11%3a00%7c10957%7c2016-10-09T12%3a35%3bflight%7c-"
},
{
"Agents": [
4035534
],
"QuoteAgeInMinutes": 5,
"Price": 20959.41,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ftgin%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
1964238
],
"QuoteAgeInMinutes": 5,
"Price": 21207.92,
"DeeplinkUrl": "/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fatin%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
4060673
],
"QuoteAgeInMinutes": 5,
"Price": 21782,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ftrea%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
3911604
],
"QuoteAgeInMinutes": 5,
"Price": 21782,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fsast%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
2391001
],
"QuoteAgeInMinutes": 5,
"Price": 21782,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http1.prod_0148f8394d6c2b79a407121f74dce6e1%26commercial_filters%3dfalse%26q_datetime_utc%3d2016-10-02T12%3a09%3a13"
},
{
"Agents": [
4260937
],
"QuoteAgeInMinutes": 5,
"Price": 22217.64,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fviai%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
3929744
],
"QuoteAgeInMinutes": 5,
"Price": 22417.66,
"DeeplinkUrl": "deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http32672%26passengers%3d1%2c0%2c0%26channel%3ddataapi%26cabin_class%3deconomy%26facilitated%3dfalse%26ticket_price%3d22417.66%26is_npt%3dfalse%26is_multipart%3dfal
}
],
"BookingDetailsLink": {
"Uri": "/apiservices/pricing/v1.0/97d115d901944a33a4084a4a3170905f_ecilpojl_A1EA190098863E15CE039BCA9C3B1D16/booking",
"Body": "OutboundLegId=12627-1610091100-AI-1-11712-1610091515&InboundLegId=",
"Method": "PUT"
}
},
{
"OutboundLegId": "12627-1610090820-9W,AI-1-11712-1610091515",
"PricingOptions": [
{
"Agents": [
1963108
],
"QuoteAgeInMinutes": 5,
"Price": 37113.61,
"DeeplinkUrl": "/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fat24%2f1%2f12627.11712.2016-10-09%2fair%2ftrava%2fflights%3fitinerary%3dflight%7c-32177%7c2367%7c12627%7c2016-"
},
{
"Agents": [
2176206
],
"QuoteAgeInMinutes": 5,
"Price": 38374,
"DeeplinkUrl": "/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fcpin%2f1%2f12627.11712.2016-10-09%2fair%2ftrava%2fflights%3fitinerary%3dflight%7c-32177%7c2367%7c12627%7c2016-10-09T08%3a20%7c10957%7c2016-10-09T09%3a45%3bflight%7c-"
},
{
"Agents": [
4056270
],
"QuoteAgeInMinutes": 5,
"Price": 38854.31,
"DeeplinkUrl": "http://partners.api.skyscanner.net/apiservices/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2ftpin%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
1964238
],
"QuoteAgeInMinutes": 5,
"Price": 39604.31,
"DeeplinkUrl": "/deeplink/v2?_cje=9CRwSnJAYX4dZyvkLfQf7nyRn0MxGbhiKjD2KHvGPF9n99euZVUDq%2bzBrzQGTfTH&url=http%3a%2f%2fwww.apideeplink.com%2ftransport_deeplink%2f4.0%2fIN%2fen-us%2fINR%2fatin%2f1%2f12627.11712.2016-10-"
},
{
"Agents": [
2627411
],
"QuoteAgeInMinutes": 5,
"Price": 39932.95,
"DeeplinkUrl": "/deeplink/v2?_1.prod_8365f3bbc5ef11ab38406bb350796374%26commercial_filters%3dfalse%26q_datetime_utc%3d2016-10-02T12%3a09%3a12"
},
{
"Agents": [
2042574
],
"QuoteAgeInMinutes": 5,
"Price": 43940.34,
"DeeplinkUrl": "/deeplink/v2?32672%26passengers%3d1%2c0%2c0%26channel%3ddataapi%26cabin_class%3deconomy%26facilitated%3dfalse%26ticket_price%3d43940.34%26is_npt%3dfalse%26is_multipart%3dfalse%26client_id%3dskyscanner_b2b%26request_id%3dd4cc5531-1a4b-4c76-a063-447e7a8baeea%26deeplink_ids%3dap-northeast-1.prod_0b228b45aaf97f3276f40ee4109e8faf%26commercial_filters%3dfalse%26q_datetime_utc%3d2016-10-02T12%3a09%3a13"
}
],
"BookingDetailsLink": {
"Uri": "/apiservices/pricing/v1.0/97d115d901944a33a4084a4a3170905f_ecilpojl_A1EA190098863E15CE039BCA9C3B1D16/booking",
"Body": "OutboundLegId=12627-1610090820-9W,AI-1-11712-1610091515&InboundLegId=",
"Method": "PUT"
}
}
],
"Legs": [
{
"Id": "12627-1610091100-AI-1-11712-1610091515",
"SegmentIds": [
1,
2
],
"OriginStation": 12627,
"DestinationStation": 11712,
"Departure": "2016-10-09T11:00:00",
"Arrival": "2016-10-09T15:15:00",
"Duration": 255,
"JourneyMode": "Flight",
"Stops": [
10957
],
"Carriers": [
841
],
"OperatingCarriers": [
841
],
"Directionality": "Outbound",
"FlightNumbers": [
{
"FlightNumber": "446",
"CarrierId": 841
},
{
"FlightNumber": "433",
"CarrierId": 841
}
]
},
{
"Id": "12627-1610090820-9W,AI-1-11712-1610091515",
"SegmentIds": [
3,
2
],
"OriginStation": 12627,
"DestinationStation": 11712,
"Departure": "2016-10-09T08:20:00",
"Arrival": "2016-10-09T15:15:00",
"Duration": 415,
"JourneyMode": "Flight",
"Stops": [
10957
],
"Carriers": [
471,
841
],
"OperatingCarriers": [
471,
841
],
"Directionality": "Outbound",
"FlightNumbers": [
{
"FlightNumber": "433",
"CarrierId": 841
},
{
"FlightNumber": "2367",
"CarrierId": 471
}
]
}
],
"Segments": [
{
"Id": 1,
"OriginStation": 12627,
"DestinationStation": 10957,
"DepartureDateTime": "2016-10-09T11:00:00",
"ArrivalDateTime": "2016-10-09T12:35:00",
"Carrier": 841,
"OperatingCarrier": 841,
"Duration": 95,
"FlightNumber": "446",
"JourneyMode": "Flight",
"Directionality": "Outbound"
},
{
"Id": 2,
"OriginStation": 10957,
"DestinationStation": 11712,
"DepartureDateTime": "2016-10-09T13:40:00",
"ArrivalDateTime": "2016-10-09T15:15:00",
"Carrier": 841,
"OperatingCarrier": 841,
"Duration": 95,
"FlightNumber": "433",
"JourneyMode": "Flight",
"Directionality": "Outbound"
},
{
"Id": 3,
"OriginStation": 12627,
"DestinationStation": 10957,
"DepartureDateTime": "2016-10-09T08:20:00",
"ArrivalDateTime": "2016-10-09T09:45:00",
"Carrier": 471,
"OperatingCarrier": 471,
"Duration": 85,
"FlightNumber": "2367",
"JourneyMode": "Flight",
"Directionality": "Outbound"
}
],
"Carriers": [
{
"Id": 841,
"Code": "AI",
"Name": "Air India",
"ImageUrl": "http://s1.apideeplink.com/images/airlines/AI.png",
"DisplayCode": "AI"
},
{
"Id": 471,
"Code": "9W",
"Name": "Jet Airways",
"ImageUrl": "http://s1.apideeplink.com/images/airlines/9W.png",
"DisplayCode": "9W"
}
],
"Agents": [
{
"Id": 1963108,
"Name": "Mytrip",
"ImageUrl": "http://s1.apideeplink.com/images/websites/at24.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"BookingNumber": "+448447747881",
"Type": "TravelAgent"
},
{
"Id": 2176206,
"Name": "Cheapticket.in",
"ImageUrl": "http://s1.apideeplink.com/images/websites/cpin.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": false,
"Type": "TravelAgent"
},
{
"Id": 4575202,
"Name": "Yatra.com",
"ImageUrl": "http://s1.apideeplink.com/images/websites/yatr.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"BookingNumber": "18001029900",
"Type": "TravelAgent"
},
{
"Id": 4056270,
"Name": "Tripsta",
"ImageUrl": "http://s1.apideeplink.com/images/websites/tpin.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"Type": "TravelAgent"
},
{
"Id": 1943172,
"Name": "AkbarTravels.com",
"ImageUrl": "http://s1.apideeplink.com/images/websites/akbt.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"Type": "TravelAgent"
},
{
"Id": 3987150,
"Name": "Travel2be",
"ImageUrl": "http://s1.apideeplink.com/images/websites/t2in.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"Type": "TravelAgent"
},
{
"Id": 4035534,
"Name": "Travelgenio",
"ImageUrl": "http://s1.apideeplink.com/images/websites/tgin.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"Type": "TravelAgent"
},
{
"Id": 1964238,
"Name": "airtickets",
"ImageUrl": "http://s1.apideeplink.com/images/websites/atin.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"Type": "TravelAgent"
},
{
"Id": 4060673,
"Name": "Traveasy.co.in",
"ImageUrl": "http://s1.apideeplink.com/images/websites/trea.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": false,
"Type": "TravelAgent"
},
{
"Id": 3911604,
"Name": "Sastiticket.com",
"ImageUrl": "http://s1.apideeplink.com/images/websites/sast.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": false,
"Type": "TravelAgent"
},
{
"Id": 2391001,
"Name": "EaseMyTrip.com",
"ImageUrl": "http://s1.apideeplink.com/images/websites/emti.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": false,
"Type": "TravelAgent"
},
{
"Id": 4260937,
"Name": "via.com",
"ImageUrl": "http://s1.apideeplink.com/images/websites/viai.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"Type": "TravelAgent"
},
{
"Id": 3929744,
"Name": "Simplio",
"ImageUrl": "http://s1.apideeplink.com/images/websites/simp.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": false,
"Type": "TravelAgent"
},
{
"Id": 2627411,
"Name": "GotoGate",
"ImageUrl": "http://s1.apideeplink.com/images/websites/gtas.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"Type": "TravelAgent"
},
{
"Id": 2042574,
"Name": "Bravofly",
"ImageUrl": "http://s1.apideeplink.com/images/websites/bfin.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"Type": "TravelAgent"
},
{
"Id": 1882712,
"Name": "ebookers",
"ImageUrl": "http://s1.apideeplink.com/images/websites/a178.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": true,
"Type": "TravelAgent"
},
{
"Id": 4366985,
"Name": "Wegoby.com",
"ImageUrl": "http://s1.apideeplink.com/images/websites/wgby.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": false,
"Type": "TravelAgent"
},
{
"Id": 3291237,
"Name": "My Travel Genie",
"ImageUrl": "http://s1.apideeplink.com/images/websites/mtge.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": false,
"Type": "TravelAgent"
},
{
"Id": 3588558,
"Name": "Tripair",
"ImageUrl": "http://s1.apideeplink.com/images/websites/pein.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": false,
"Type": "TravelAgent"
},
{
"Id": 2834897,
"Name": "Air India",
"ImageUrl": "http://s1.apideeplink.com/images/websites/inda.png",
"Status": "UpdatesComplete",
"OptimisedForMobile": false,
"BookingNumber": "18001801407",
"Type": "Airline"
}
],
"Places": [
{
"Id": 12627,
"ParentId": 3462,
"Code": "IXL",
"Type": "Airport",
"Name": "Leh"
},
{
"Id": 10957,
"ParentId": 3401,
"Code": "DEL",
"Type": "Airport",
"Name": "New Delhi"
},
{
"Id": 11712,
"ParentId": 3424,
"Code": "GAY",
"Type": "Airport",
"Name": "Gaya"
},
{
"Id": 3462,
"ParentId": 170,
"Code": "IXL",
"Type": "City",
"Name": "Leh"
},
{
"Id": 3401,
"ParentId": 170,
"Code": "DEL",
"Type": "City",
"Name": "New Delhi"
},
{
"Id": 3424,
"ParentId": 170,
"Code": "GAY",
"Type": "City",
"Name": "Gaya"
},
{
"Id": 170,
"Code": "IN",
"Type": "Country",
"Name": "India"
}
],
"Currencies": [
{
"Code": "INR",
"Symbol": "₹",
"ThousandsSeparator": ",",
"DecimalSeparator": ".",
"SymbolOnLeft": true,
"SpaceBetweenAmountAndSymbol": false,
"RoundingCoefficient": 0,
"DecimalDigits": 2
}
]
}
If you are able to pull the json data then try using this js script:
Make sure to add jQuery
Change the value of the url variable with the session poll url you created
NOTE: Please take note that you will encounter cross origin error when you try to run this script here.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
( function( window, document, $ ){
var app = {};
app.init = function()
{
app.flightsGeo();
};
app.flightsGeo = function( )
{
// the session poll url you created
var url = 'http://business.skyscanner.net/apiservices/pricing/hk1/v1.0/<sessionKey>?apikey=<apikey>';
$.ajax({
type: "GET",
url: url,
dataType: 'json',
success: function( response ){
var itineraries = response.Itineraries;
var agents = response.Agents;
var legs = response.Legs;
var carriers = response.Carriers;
var places = response.Places;
$.each(itineraries, function( itineraryKey, itineraryVal ){
var inbound = app.getObjects( legs, 'Id', itineraryVal.InboundLegId),
inDepartureTime = inbound[0].Departure,
inArrivalTime = inbound[0].Arrival,
inDepartureDate = inbound[0].Departure,
inArrivalDate = inbound[0].Arrival,
inOrigin = app.getObjects( places, 'Id', inbound[0].DestinationStation),
inDestination = app.getObjects( places, 'Id', inbound[0].OriginStation),
inCarriers = app.getObjects( carriers, 'Id', inbound[0].OperatingCarriers[0]);
var outbound = app.getObjects( legs, 'Id', itineraryVal.OutboundLegId),
outDepartureTime = outbound[0].Departure,
outArrivalTime = outbound[0].Arrival,
outDepartureDate = outbound[0].Departure,
outArrivalDate = outbound[0].Arrival,
outOrigin = app.getObjects( places, 'Id', outbound[0].DestinationStation),
outDestination = app.getObjects( places, 'Id', outbound[0].OriginStation),
outCarriers = app.getObjects( carriers, 'Id', outbound[0].OperatingCarriers[0]);
var agent = app.getObjects( agents, 'Id', itineraryVal.PricingOptions[0].Agents[0]);
var price = itineraryVal.PricingOptions[0].Price.toFixed(2);
var permalink = itineraryVal.PricingOptions[0].DeeplinkUrl;
var time = itineraryVal.PricingOptions[0].QuoteAgeInMinutes;
// NEW FORMAT OF DATA
var data = {
agent : agent,
price : price,
time : time,
permalink : permalink,
inbound : {
time : {
departure : inDepartureTime,
arrival : inArrivalTime
},
date : {
departure : inDepartureDate,
arrival : inArrivalDate
},
station : {
origin : inOrigin,
destination : inDestination
},
carriers : inCarriers
},
outbound : {
time : {
departure : outDepartureTime,
arrival : outArrivalTime
},
date : {
departure : outDepartureDate,
arrival : outArrivalDate
},
station : {
origin : outOrigin,
destination : outDestination
},
carriers : outCarriers
}
};
// will display the NEW FORMAT OF DATA
console.log( data );
});
},
error: function( error ){
console.log( error );
}
});
};
app.displayData = function( data )
{
console.log( data );
};
app.getObjects = function(obj, key, val) {
var objects = [];
for (var i in obj) {
if (!obj.hasOwnProperty(i)) continue;
if (typeof obj[i] == 'object') {
objects = objects.concat(app.getObjects(obj[i], key, val));
} else
//if key matches and value matches or if key matches and value is not passed (eliminating the case where key matches but passed value does not)
if (i == key && obj[i] == val || i == key && val == '') { //
objects.push(obj);
} else if (obj[i] == val && key == ''){
//only add if the object is not already in the array
if (objects.lastIndexOf(obj) == -1){
objects.push(obj);
}
}
}
return objects;
};
$(document).ready( app.init );
return app;
})( window, document, jQuery );
</script>
P.S. I hope this will helps you the idea how to get the data you need.
I'll show a basic example of how to parse. Take the following sample JSON.
http://api.androidhive.info/contacts/
How to get the contacts list.
JSONObject jsonObj = new JSONObject("Your JSON String here");
JSONArray contacts = jsonObj.optJSONArray("contacts");
How to calculate the phone number
//Get first contact
JSONObject firstContact = contacts.optJSONObject(0);
JSONObject phone = firstContact.optJSONObject("phone");
String mobileNo = phone.optString("mobile");
Similarly you can apply this technique to your JSON.

Unable to parse a JSON containing complex jsonarrays and Json objects

I have got a following json,
[
"GetStatutoryMappingsSuccess",
{
"statutory_mappings": {
"5": {
"geography_ids": [
2,
1
],
"approval_status": 0,
"approval_status_text": "Pending",
"compliance_names": [
{
"url": null,
"compliance_name": "Every Month Task"
}
],
"statutory_nature_name": "Central",
"country_id": 1,
"domain_name": "Labour Law",
"industry_names": "Factory, Office",
"is_active": true,
"statutory_nature_id": 2,
"statutory_ids": [
2
],
"country_name": "iNDIA",
"industry_ids": [
1,
2
],
"geography_mappings": [
"iNDIA >> North Region",
"iNDIA >> South Region"
],
"compliances": [
{
"description": "sDSFDSf",
"is_active": true,
"repeats_type_id": 2,
"statutory_provision": "Provision",
"compliance_task": "Every Month Task",
"format_file_list": null,
"duration": null,
"document_name": null,
"penal_consequences": "",
"duration_type_id": null,
"frequency_id": 2,
"repeats_every": 1,
"statutory_dates": [
{
"statutory_month": 1,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 2,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 3,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 4,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 5,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 6,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 7,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 8,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 9,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 10,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 11,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
},
{
"statutory_month": 12,
"statutory_date": 10,
"trigger_before_days": 10,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 12
}
],
"statutory_mappings": [
"POG Act>>State Rule All"
],
"domain_id": 2
},
"6": {
"geography_ids": [
17,
16
],
"approval_status": 0,
"approval_status_text": "Pending",
"compliance_names": [
{
"url": null,
"compliance_name": "One Time Task"
},
{
"url": null,
"compliance_name": "Daily Task"
},
{
"url": null,
"compliance_name": "Monthly Task"
}
],
"statutory_nature_name": "Central",
"country_id": 3,
"domain_name": "Labour Law",
"industry_names": "Factory, Office",
"is_active": true,
"statutory_nature_id": 2,
"statutory_ids": [
3
],
"country_name": "Singapore",
"industry_ids": [
1,
2
],
"geography_mappings": [
"Singapore >> North Region",
"Singapore >> South Region"
],
"compliances": [
{
"description": "FDSFDS",
"is_active": true,
"repeats_type_id": null,
"statutory_provision": "Central Rule",
"compliance_task": "One Time Task",
"format_file_list": null,
"duration": null,
"document_name": null,
"penal_consequences": "",
"duration_type_id": null,
"frequency_id": 1,
"repeats_every": null,
"statutory_dates": [
{
"statutory_month": 1,
"statutory_date": 10,
"trigger_before_days": 25,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 13
},
{
"description": "SDFDSF",
"is_active": true,
"repeats_type_id": 1,
"statutory_provision": "Central Rule",
"compliance_task": "Daily Task",
"format_file_list": null,
"duration": null,
"document_name": null,
"penal_consequences": "",
"duration_type_id": null,
"frequency_id": 2,
"repeats_every": 2,
"statutory_dates": [
{
"statutory_month": null,
"statutory_date": null,
"trigger_before_days": 25,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 14
},
{
"description": "DSDSD",
"is_active": true,
"repeats_type_id": 2,
"statutory_provision": "Central Rule",
"compliance_task": "Monthly Task",
"format_file_list": null,
"duration": null,
"document_name": null,
"penal_consequences": "",
"duration_type_id": null,
"frequency_id": 2,
"repeats_every": 1,
"statutory_dates": [
{
"statutory_month": null,
"statutory_date": 3,
"trigger_before_days": 30,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 15
}
],
"statutory_mappings": [
"SOG Act"
],
"domain_id": 2
},
"7": {
"geography_ids": [
2
],
"approval_status": 0,
"approval_status_text": "Pending",
"compliance_names": [
{
"url": null,
"compliance_name": "… … … ……… …dfg dfg ⁜ ⁜ ⁜ sdfsdsf sf sdfsd sdf sff⁙ ⁙ ⁙ ⁙ ⁙"
},
{
"url": null,
"compliance_name": "⁕⁖ ⁗⁘ ⁙⁚ ⁛ ⁜gdfg ⁝ ⁞ ⁤⁥ ⁰⁵ ⁿ ⁑ ⁒ ⁓ ⁋ df sdf sdfdgf dfg dg"
},
{
"url": null,
"compliance_name": "```````````````"
}
],
"statutory_nature_name": "Central",
"country_id": 1,
"domain_name": "Labour Law",
"industry_names": "Factory",
"is_active": true,
"statutory_nature_id": 2,
"statutory_ids": [
2
],
"country_name": "iNDIA",
"industry_ids": [
1
],
"geography_mappings": [
"iNDIA >> North Region"
],
"compliances": [
{
"description": "Application for registration and grant of renewal of licen dfgce for the year … …… …… ⁜ ⁜",
"is_active": true,
"repeats_type_id": null,
"statutory_provision": "sadsad",
"compliance_task": "… … … ……… …dfg dfg ⁜ ⁜ ⁜ sdfsdsf sf sdfsd sdf sff⁙ ⁙ ⁙ ⁙ ⁙",
"format_file_list": null,
"duration": null,
"document_name": null,
"penal_consequences": "",
"duration_type_id": null,
"frequency_id": 1,
"repeats_every": null,
"statutory_dates": [
{
"statutory_month": 1,
"statutory_date": 4,
"trigger_before_days": null,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 16
},
{
"description": "sdfsdfdsf",
"is_active": true,
"repeats_type_id": null,
"statutory_provision": "dssfdsf",
"compliance_task": "⁕⁖ ⁗⁘ ⁙⁚ ⁛ ⁜gdfg ⁝ ⁞ ⁤⁥ ⁰⁵ ⁿ ⁑ ⁒ ⁓ ⁋ df sdf sdfdgf dfg dg",
"format_file_list": null,
"duration": null,
"document_name": null,
"penal_consequences": "",
"duration_type_id": null,
"frequency_id": 1,
"repeats_every": null,
"statutory_dates": [
{
"statutory_month": null,
"statutory_date": null,
"trigger_before_days": null,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 17
},
{
"description": "fghfg",
"is_active": true,
"repeats_type_id": null,
"statutory_provision": "gfghfg",
"compliance_task": "```````````````",
"format_file_list": null,
"duration": null,
"document_name": null,
"penal_consequences": "",
"duration_type_id": null,
"frequency_id": 1,
"repeats_every": null,
"statutory_dates": [
{
"statutory_month": null,
"statutory_date": null,
"trigger_before_days": null,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 18
}
],
"statutory_mappings": [
"POG Act>>State Rule All"
],
"domain_id": 2
},
"10": {
"geography_ids": [
1
],
"approval_status": 0,
"approval_status_text": "Pending",
"compliance_names": [
{
"url": null,
"compliance_name": "One Time Task"
},
{
"url": null,
"compliance_name": "One Time Tasss replicate"
}
],
"statutory_nature_name": "Central",
"country_id": 1,
"domain_name": "Labour Law",
"industry_names": "Factory",
"is_active": true,
"statutory_nature_id": 2,
"statutory_ids": [
7
],
"country_name": "iNDIA",
"industry_ids": [
1
],
"geography_mappings": [
"iNDIA >> South Region"
],
"compliances": [
{
"description": "DSFSDFDS",
"is_active": true,
"repeats_type_id": null,
"statutory_provision": "Central Rule",
"compliance_task": "One Time Task",
"format_file_list": null,
"duration": null,
"document_name": null,
"penal_consequences": "",
"duration_type_id": null,
"frequency_id": 1,
"repeats_every": null,
"statutory_dates": [
{
"statutory_month": 4,
"statutory_date": 12,
"trigger_before_days": 25,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 21
},
{
"description": "sdfds",
"is_active": true,
"repeats_type_id": null,
"statutory_provision": "Central Rule",
"compliance_task": "One Time Tasss replicate",
"format_file_list": null,
"duration": null,
"document_name": null,
"penal_consequences": "",
"duration_type_id": null,
"frequency_id": 1,
"repeats_every": null,
"statutory_dates": [
{
"statutory_month": 5,
"statutory_date": 4,
"trigger_before_days": 30,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 22
}
],
"statutory_mappings": [
"ESI Act>>Rule 1A"
],
"domain_id": 2
},
"11": {
"geography_ids": [
1
],
"approval_status": 0,
"approval_status_text": "Pending",
"compliance_names": [
{
"url": "compliance_format/statutory-mapping-table-reference-c4f43cb06e24410fbed1f4d96a3afff8.xls",
"compliance_name": "Docu - One Time Task"
},
{
"url": "compliance_format/md5-decrypt-508ffc6b93de45828b38abc9ce21ee18.py",
"compliance_name": "DOC - On Occurance Task"
}
],
"statutory_nature_name": "Central",
"country_id": 1,
"domain_name": "Labour Law",
"industry_names": "Factory",
"is_active": true,
"statutory_nature_id": 2,
"statutory_ids": [
7
],
"country_name": "iNDIA",
"industry_ids": [
1
],
"geography_mappings": [
"iNDIA >> South Region"
],
"compliances": [
{
"description": "DSDSF",
"is_active": true,
"repeats_type_id": null,
"statutory_provision": "Doc",
"compliance_task": "One Time Task",
"format_file_list": [
{
"file_content": "compliance_format/statutory-mapping-table-reference-c4f43cb06e24410fbed1f4d96a3afff8.xls",
"file_name": "statutory-mapping-table-reference-c4f43cb06e24410fbed1f4d96a3afff8.xls",
"file_size": 11264
}
],
"duration": null,
"document_name": "Docu",
"penal_consequences": "sdfdsf",
"duration_type_id": null,
"frequency_id": 1,
"repeats_every": null,
"statutory_dates": [
{
"statutory_month": null,
"statutory_date": null,
"trigger_before_days": null,
"repeat_by": "dayofmonth"
}
],
"compliance_id": 25
},
{
"description": "sddsfdsf",
"is_active": true,
"repeats_type_id": null,
"statutory_provision": "Doc",
"compliance_task": "On Occurance Task",
"format_file_list": [
{
"file_content": "compliance_format/md5-decrypt-508ffc6b93de45828b38abc9ce21ee18.py",
"file_name": "md5-decrypt-508ffc6b93de45828b38abc9ce21ee18.py",
"file_size": 739
}
],
"duration": 7,
"document_name": "DOC",
"penal_consequences": "",
"duration_type_id": 2,
"frequency_id": 4,
"repeats_every": null,
"statutory_dates": [],
"compliance_id": 23
}
],
"statutory_mappings": [
"ESI Act>>Rule 1A"
],
"domain_id": 2
},
"12": {
"geography_ids": [
1
],
"approval_status": 0,
"approval_status_text": "Pending",
"compliance_names": [
{
"url": "compliance_format/mobile-api-50d3dfd554664da1bc65935202bf63b6.txt",
"compliance_name": "Doc - Doc"
}
],
"statutory_nature_name": "Central",
"country_id": 1,
"domain_name": "Labour Law",
"industry_names": "Factory",
"is_active": true,
"statutory_nature_id": 2,
"statutory_ids": [
7
],
"country_name": "iNDIA",
"industry_ids": [
1
],
"geography_mappings": [
"iNDIA >> South Region"
],
"compliances": [
{
"description": "Doc",
"is_active": true,
"repeats_type_id": null,
"statutory_provision": "Rule IA",
"compliance_task": "Doc",
"format_file_list": [
{
"file_content": "compliance_format/mobile-api-50d3dfd554664da1bc65935202bf63b6.txt",
"file_name": "mobile-api-50d3dfd554664da1bc65935202bf63b6.txt",
"file_size": 6733
}
],
"duration": 1,
"document_name": "Doc",
"penal_consequences": "sdfd",
"duration_type_id": 1,
"frequency_id": 4,
"repeats_every": null,
"statutory_dates": [],
"compliance_id": 24
}
],
"statutory_mappings": [
"ESI Act>>Rule 1A"
],
"domain_id": 2
}
}
}
]
Im trying to parse it as follows,
for (int i = 0; i < response.length(); i++) {
try {
// Toast.makeText(getActivity(), response.toString(), Toast.LENGTH_SHORT).show();
JSONObject value = response.getJSONObject(i);
JSONObject statutory_mappings = value.getJSONObject("statutory_mappings");
Iterator<String> keys = statutory_mappings.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
JSONObject statMap = statutory_mappings.getJSONObject(key);
//iterate geography id's in case if there comes any necessity
JSONArray geography_ids = statMap.getJSONArray("geography_ids");
JSONObject approval_status = statMap.getJSONObject("approval_status");
String approval_status_text = statMap.getString("approval_status_text");
JSONArray compliance_names = statMap.getJSONArray("compliance_names");
String statutory_nature_name = statMap.getString("statutory_nature_name");
String country_id = statMap.getString("country_id");
String domain_name = statMap.getString("domain_name");
String industry_names = statMap.getString("industry_names");
String is_active = statMap.getString("is_active");
String statutory_nature_id = statMap.getString("statutory_nature_id");
JSONArray statutory_ids = statMap.getJSONArray("statutory_ids");
String country_name = statMap.getString("country_name");
JSONArray industry_ids = statMap.getJSONArray("industry_ids");
JSONArray geography_mappings = statMap.getJSONArray("geography_mappings");
JSONArray compliances = statMap.getJSONArray("compliances");
String compliance_id = statMap.getString("compliance_id");
JSONArray inner_statutory_mappings = statMap.getJSONArray("statutory_mappings");
String domain_id = statMap.getString("domain_id");
String logs = geography_ids + ""+ approval_status + " "+approval_status_text + " "+ compliance_names + " "+ statutory_nature_name + " "+country_id + " "+domain_name + " "+ industry_names + " "+is_active + " "+statutory_ids + " "+statutory_nature_id + " "+ country_name + " "+industry_ids + " "+ geography_mappings + " "+compliances + " "+compliance_id + " "+inner_statutory_mappings + " "+domain_id;
Toast.makeText(getActivity(),geography_ids.toString(),Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
The problem is that Im not be able to parse it. It prints geography_ids but not approval status and other values. Why is that so? Am I missing any logic?
Problem 1
Your json has this format:
[
"GetStatutoryMappingsSuccess",
{...}
]
So when you try to itterate over this array you will get 1 Exeption:
org.json.JSONException: JSONArray[0] is not a JSONObject. because 1-st element is not a JsonObject but a String. That is why you'd better just use JSONObject value = new JSONArray(json).getJSONObject(1); instead of for loop
Problem 2
Inside 2-nd object you have
{
"statutory_mappings": {
"5": {
"approval_status": 0,
...
}
}
}
And your parsing code should work, but "approval_status" is integer , so instead of
JSONObject approval_status = statMap.getJSONObject("approval_status");
should be:
int approval_status = statMap.getInt("approval_status");
// Same problem for:
int country_id = statMap.getInt("country_id");
boolean is_active = statMap.getBoolean("is_active");
int statutory_nature_id = statMap.getInt("statutory_nature_id");
int domain_id = statMap.getInt("domain_id");
Problem 3
There is also problem with compliance_id and json looks like this
"compliances": [
{
// ... some fields here
"compliance_id": 13
},
{
// ... some fields here
"compliance_id": 14
},
...
]
So there is no point to print compliances in your log string and if you really want to get compliance_id of aach element in array you have to itterate over them like this
JSONArray compliancesArr = statMap.getJSONArray("compliances");
for(int i = 0; i < compliancesArr.length();i++){
JSONObject compliancesObj = compliancesArr.getJSONObject(i);
int compliance_id = compliancesObj.getInt("compliance_id");
}
PS. Gson or Jackson will make your parsing code much easier.

Categories

Resources