Unable to parse a JSON containing complex jsonarrays and Json objects - android

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.

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 to store response to object in flutter using dio

I am using dio by using this I am passing form data and getting response but I am unable to store data to object. Please help me
It is giving response when I am printing response.data but I am not getting how to store the response to object.
class MainActivityGrid extends StatefulWidget {
#override
_MainActivityGridState createState() => _MainActivityGridState();
}
class _MainActivityGridState extends State<MainActivityGrid> {
// List<ImageModel>images= [];
#override
Widget build(BuildContext context) {
return MaterialApp(
home: new Scaffold(
appBar: AppBar(
title: new Text("IPTV"),
),
body: new Center(
child: new RaisedButton(
child: new Text("Button"), onPressed: fetchImage),
),
),
);
}
Future<String> fetchImage() async {
String url = "http://xxxxxx:xxx/onnet_api/mediaList.php";
Response response;
Dio dio = new Dio();
FormData formData = new FormData.from(
{"publisherid": 102, "tag": "media", "subtag": "list"});
// counter ++;
response = await dio.post(url, data: formData);
// dio.interceptors.add(LogInterceptor(responseBody: fa));
//int status = response.data["status"]["data"];
//Map responseBody = response.data;
//loginResponse = new LoginResponse.fromJson(json.decode(response.data));
print(response.data["data"][0]);
//ImageModel imageModel = new ImageModel.fromJson(json.decode(response.data[]));
//print('response media: $status');
/* setState(() {
//images.add(imageModel);
});*/
}
}
my JSON response for my API is showing like this below: please try to help me in this.
{
"status": 1,
"data": [
{
"id": "0_314t2peg",
"name": "Countdown",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_314t2peg/version/100002",
"plays": 12,
"categories": "News>BBC,News>CNBC,News>PublicTV,News>TV9,Shows>Thriller,Shows>Regional",
"categoriesIds": "19,20,18,17,13,16",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_314t2peg/format/url/protocol/http",
"duration": 13,
"createdAt": "28/11/18 11:26:39",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_joyzmp2z",
"name": "voice 4k",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_joyzmp2z/version/100002",
"plays": 14,
"categories": "News>BBC,News>CNBC,News>PublicTV,News>TV9,Shows>Thriller,Shows>Regional",
"categoriesIds": "19,20,18,17,13,16",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_joyzmp2z/format/url/protocol/http",
"duration": 20,
"createdAt": "28/11/18 11:25:56",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_yndwskxv",
"name": "news",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_yndwskxv/version/100012",
"plays": 6,
"categories": "News>BBC,News>TV9,Shows>Regional",
"categoriesIds": "19,17,16",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_yndwskxv/format/url/protocol/http",
"duration": 17,
"createdAt": "28/11/18 11:24:12",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_jd7hul0b",
"name": "GB10Sec",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_jd7hul0b/version/100002",
"plays": 8,
"categories": "Shows>Thriller,Shows>Action,Shows>Sci-Fi",
"categoriesIds": "13,15,14",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_jd7hul0b/format/url/protocol/http",
"duration": 10,
"createdAt": "28/11/18 11:14:40",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_bz9qlkle",
"name": "Thugs Of Hindostan",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_bz9qlkle/version/100002",
"plays": 0,
"categories": null,
"categoriesIds": null,
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_bz9qlkle/format/url/protocol/http",
"duration": 218,
"createdAt": "28/11/18 11:08:45",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_swm5unow",
"name": "Shivaay",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_swm5unow/version/100002",
"plays": 0,
"categories": null,
"categoriesIds": null,
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_swm5unow/format/url/protocol/http",
"duration": 230,
"createdAt": "28/11/18 11:08:23",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_1n1qg0hq",
"name": "Rocky Handsome",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_1n1qg0hq/version/100012",
"plays": 9,
"categories": "Movies>Drama,Movies>Sci-Fi",
"categoriesIds": "22,24",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_1n1qg0hq/format/url/protocol/http",
"duration": 184,
"createdAt": "28/11/18 11:08:03",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_3vk4o4ie",
"name": "Genius",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_3vk4o4ie/version/100012",
"plays": 5,
"categories": "Movies>Drama,Movies>Sci-Fi",
"categoriesIds": "22,24",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_3vk4o4ie/format/url/protocol/http",
"duration": 200,
"createdAt": "28/11/18 11:07:46",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_jb8en5kn",
"name": "Commando",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_jb8en5kn/version/100012",
"plays": 2,
"categories": "Movies>Thriller,Movies>Drama,Movies>Sci-Fi",
"categoriesIds": "23,22,24",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_jb8en5kn/format/url/protocol/http",
"duration": 162,
"createdAt": "28/11/18 11:07:25",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_es5vzzca",
"name": "Action Jackson",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_es5vzzca/version/100002",
"plays": 0,
"categories": "Movies>Thriller,Movies>Drama,Movies>Sci-Fi",
"categoriesIds": "23,22,24",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_es5vzzca/format/url/protocol/http",
"duration": 175,
"createdAt": "28/11/18 11:06:13",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_2tfugvsm",
"name": "jellyfish-25-mbps-hd-hevc",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_2tfugvsm/version/100002",
"plays": 0,
"categories": null,
"categoriesIds": null,
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_2tfugvsm/format/url/protocol/http",
"duration": 30,
"createdAt": "22/11/18 09:05:26",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_z5i5fmiw",
"name": "small (3)",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_z5i5fmiw/version/100022",
"plays": 1,
"categories": null,
"categoriesIds": null,
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_z5i5fmiw/format/url/protocol/http",
"duration": 6,
"createdAt": "22/11/18 06:41:15",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_0i4hbs9o",
"name": "dolbycanyon",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_0i4hbs9o/version/100012",
"plays": 1,
"categories": null,
"categoriesIds": null,
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_0i4hbs9o/format/url/protocol/http",
"duration": 38,
"createdAt": "22/11/18 06:38:13",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_wbd3wu38",
"name": "Mary and little lamb",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_wbd3wu38/version/100002",
"plays": 3,
"categories": "Shows>Sci-Fi,Shows>Regional,Movies>Action",
"categoriesIds": "14,16,21",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_wbd3wu38/format/url/protocol/http",
"duration": 184,
"createdAt": "12/11/18 10:36:17",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_k4unuqi2",
"name": "Johny Johny",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_k4unuqi2/version/100002",
"plays": 2,
"categories": "Shows>Sci-Fi,Movies>Action",
"categoriesIds": "14,21",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_k4unuqi2/format/url/protocol/http",
"duration": 186,
"createdAt": "12/11/18 10:36:17",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_3w4xjt5x",
"name": "One Little Flower",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_3w4xjt5x/version/100012",
"plays": 7,
"categories": "TV>Entertainment",
"categoriesIds": "25",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_3w4xjt5x/format/url/protocol/http",
"duration": 83,
"createdAt": "12/11/18 10:20:14",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_w64yjfen",
"name": "I'm A Little Teapot",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_w64yjfen/version/100012",
"plays": 9,
"categories": "Shows>Action,TV>Shows",
"categoriesIds": "15,11",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_w64yjfen/format/url/protocol/http",
"duration": 104,
"createdAt": "12/11/18 10:20:14",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_591qnfyf",
"name": "Little Jack Horner",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_591qnfyf/version/100002",
"plays": 93,
"categories": "Shows>Regional,Movies>Action,TV>Shows",
"categoriesIds": "16,21,11",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_591qnfyf/format/url/protocol/http",
"duration": 87,
"createdAt": "12/11/18 10:18:49",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_n1wvco0o",
"name": "My School",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_n1wvco0o/version/100012",
"plays": 21,
"categories": "TV>Shows",
"categoriesIds": "11",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_n1wvco0o/format/url/protocol/http",
"duration": 75,
"createdAt": "12/11/18 10:18:49",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_srtxu635",
"name": "Hop a little",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_srtxu635/version/100012",
"plays": 24,
"categories": "Movies>Thriller,Movies>Action,TV>Shows",
"categoriesIds": "23,21,11",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_srtxu635/format/url/protocol/http",
"duration": 108,
"createdAt": "12/11/18 10:18:49",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_uuu7jii2",
"name": "Come Little Children",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_uuu7jii2/version/100002",
"plays": 4,
"categories": "Movies>Sci-Fi,Movies>Action,TV>Shows",
"categoriesIds": "24,21,11",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_uuu7jii2/format/url/protocol/http",
"duration": 94,
"createdAt": "12/11/18 10:16:00",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_9ld6kzph",
"name": "story telling",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_9ld6kzph/version/100002",
"plays": 2,
"categories": "Movies>Drama,Movies>Action",
"categoriesIds": "22,21",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_9ld6kzph/format/url/protocol/http",
"duration": 73,
"createdAt": "12/11/18 10:16:00",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_cz6egmc9",
"name": "Tenali Raman In English",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_cz6egmc9/version/100002",
"plays": 1,
"categories": "Movies>Action,Shows>Thriller",
"categoriesIds": "21,13",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_cz6egmc9/format/url/protocol/http",
"duration": 151,
"createdAt": "12/11/18 10:16:00",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_pj8ansdd",
"name": "The two frogs",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_pj8ansdd/version/100002",
"plays": 1,
"categories": "News>TV9,Movies>Action",
"categoriesIds": "17,21",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_pj8ansdd/format/url/protocol/http",
"duration": 141,
"createdAt": "12/11/18 10:16:00",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_7wy5icdl",
"name": "Twinkle Twinkle",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_7wy5icdl/version/100002",
"plays": 1,
"categories": "News>CNBC",
"categoriesIds": "20",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_7wy5icdl/format/url/protocol/http",
"duration": 181,
"createdAt": "12/11/18 10:16:00",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_0l7xkwee",
"name": "Two little hands",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_0l7xkwee/version/100002",
"plays": 5,
"categories": "Movies>Action,News>BBC",
"categoriesIds": "21,19",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_0l7xkwee/format/url/protocol/http",
"duration": 59,
"createdAt": "12/11/18 10:16:00",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_58md9gkm",
"name": "amazoneco",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_58md9gkm/version/100002",
"plays": 0,
"categories": "News>PublicTV",
"categoriesIds": "18",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_58md9gkm/format/url/protocol/http",
"duration": 36,
"createdAt": "05/11/18 12:01:44",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_f90klu3n",
"name": "arunicecream",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_f90klu3n/version/100012",
"plays": 2,
"categories": null,
"categoriesIds": null,
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_f90klu3n/format/url/protocol/http",
"duration": 15,
"createdAt": "05/11/18 12:01:44",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_hmr8atha",
"name": "bahubalitrailer",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_hmr8atha/version/100012",
"plays": 11,
"categories": "TV>Songs,Shows>Thriller,Shows>Regional",
"categoriesIds": "12,13,16",
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_hmr8atha/format/url/protocol/http",
"duration": 21,
"createdAt": "05/11/18 12:01:44",
"status": 2,
"statusc": 2,
"mediaType": 1
},
{
"id": "0_kzwqw8eq",
"name": "BigData",
"thumbnailUrl": "http://onnet-video-platform/p/102/sp/10200/thumbnail/entry_id/0_kzwqw8eq/version/100012",
"plays": 1,
"categories": null,
"categoriesIds": null,
"dataUrl": "http://159.65.156.204/p/102/sp/10200/playManifest/entryId/0_kzwqw8eq/format/url/protocol/http",
"duration": 93,
"createdAt": "05/11/18 12:01:44",
"status": 2,
"statusc": 2,
"mediaType": 1
}
],
"totalRecord": 30
}
No need to use Json Decode for Dio. You can do something like below:
Response responseval=await dio.post(url,options: Options(headers: headers));
var name=responseval.data['username'];
var id=responseeval.data['id'];
Convert Bean or Dio form your response like this or you can use this to convert JSON reponse to dart bean
import 'dart:convert';
Welcome welcomeFromJson(String str) {
final jsonData = json.decode(str);
return Welcome.fromJson(jsonData);
}
String welcomeToJson(Welcome data) {
final dyn = data.toJson();
return json.encode(dyn);
}
class Welcome {
int status;
List<Datum> data;
int totalRecord;
Welcome({
this.status,
this.data,
this.totalRecord,
});
factory Welcome.fromJson(Map<String, dynamic> json) => new Welcome(
status: json["status"] == null ? null : json["status"],
data: json["data"] == null ? null : new List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))),
totalRecord: json["totalRecord"] == null ? null : json["totalRecord"],
);
Map<String, dynamic> toJson() => {
"status": status == null ? null : status,
"data": data == null ? null : new List<dynamic>.from(data.map((x) => x.toJson())),
"totalRecord": totalRecord == null ? null : totalRecord,
};
}
class Datum {
String id;
String name;
String thumbnailUrl;
int plays;
String categories;
String categoriesIds;
String dataUrl;
int duration;
String createdAt;
int status;
int statusc;
int mediaType;
Datum({
this.id,
this.name,
this.thumbnailUrl,
this.plays,
this.categories,
this.categoriesIds,
this.dataUrl,
this.duration,
this.createdAt,
this.status,
this.statusc,
this.mediaType,
});
factory Datum.fromJson(Map<String, dynamic> json) => new Datum(
id: json["id"] == null ? null : json["id"],
name: json["name"] == null ? null : json["name"],
thumbnailUrl: json["thumbnailUrl"] == null ? null : json["thumbnailUrl"],
plays: json["plays"] == null ? null : json["plays"],
categories: json["categories"] == null ? null : json["categories"],
categoriesIds: json["categoriesIds"] == null ? null : json["categoriesIds"],
dataUrl: json["dataUrl"] == null ? null : json["dataUrl"],
duration: json["duration"] == null ? null : json["duration"],
createdAt: json["createdAt"] == null ? null : json["createdAt"],
status: json["status"] == null ? null : json["status"],
statusc: json["statusc"] == null ? null : json["statusc"],
mediaType: json["mediaType"] == null ? null : json["mediaType"],
);
Map<String, dynamic> toJson() => {
"id": id == null ? null : id,
"name": name == null ? null : name,
"thumbnailUrl": thumbnailUrl == null ? null : thumbnailUrl,
"plays": plays == null ? null : plays,
"categories": categories == null ? null : categories,
"categoriesIds": categoriesIds == null ? null : categoriesIds,
"dataUrl": dataUrl == null ? null : dataUrl,
"duration": duration == null ? null : duration,
"createdAt": createdAt == null ? null : createdAt,
"status": status == null ? null : status,
"statusc": statusc == null ? null : statusc,
"mediaType": mediaType == null ? null : mediaType,
};
}
This method returs you Reponse bean object
Future<Welcome> getMediaList() async {
String url='http://xxxxxx:xxx/onnet_api/mediaList.php';
http.Response res = await http.get(url);
final jsonData = json.decode(res.body);
var map=Map<String, dynamic>.from(jsonData);
var response=Welcome.fromJson(map);
if (res.statusCode == 200) {
return response;
} else {
throw Exception('Failed to load post');
}
}
Call this method like this
getMediaList().then((onValue){// on value is an object ot bean class //here you will be able to get members of your bean class })
and another way is to call your service is FutureBuilder<Welcome>();
You can add header and body in http.post Post url.
Future<UserResponse> loginService() async {
String qaurl = "https://www.xxxxxxxxx.com/api/loginapi.html";
var body = new Map<String, String>(); //here i defined Map ty
body['email'] =_email; // pe
body['password'] = _password;
body['return'] = 'json';
body['apikey'] = ApiKey;
http.Response res = await http.post(qaurl, body: body);
final jsonData = json.decode(res.body);
var map=Map<String, dynamic>.from(jsonData);
var loginResponse=UserResponse.fromJsonMap(map);
if (res.statusCode == 200) {
return loginResponse;
} else {
Navigator.of(context, rootNavigator: true).pop('dialog');
throw Exception('Failed to load post');
}
}

Set json response get_Infographs value in recycler view of this data

{
"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)

how can i fetch data from the server in android

I want to fetch the data from data_format_value. it return last value only. i don't know where is the error occur. i want fetch all the data_format_value.
{
"org_id": 1
"test_instance_id": 237,
"section_attributes": [
{
"section_id": 1,
"section_name": "Section-A",
"section_status": "Started",
"item_count": 5
}
],
"itemset_sections": [
{
"section_id": 1,
"section_name": "Section-A",
"timer": 30,
"section_items": [
{
"item_id": 190,
"item_type": 1,
"is_directive": 0,
"directive_content": {},
"hints": "scientists",
"item": [
{
"data_id": 877,
"data_format_id": 1,
"data_format_value": "Why haven't Indian scientists made such headway in any field after independence ?",
"item_df_sequence": 1,
"data_identifier": null
},
{
"data_id": 878,
"data_format_id": 1,
"data_format_value": "Indian scientists are not provided with up to date laboratory facilities.",
"item_df_sequence": 2,
"data_identifier": null
},
{
"data_id": 879,
"data_format_id": 1,
"data_format_value": "Indian scientists regard that knowledge of western science advances is enough for a nation to advance.",
"item_df_sequence": 3,
"data_identifier": null
}
],
"answer_choices": [
{
"correct_answer": false,
"answer_choice_id": 4,
"choice_elements": [
{
"data_id": 883,
"data_format_id": 1,
"data_format_value": "data given in both statements I and II together are not sufficient to answer the question. ",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 1
},
{
"correct_answer": false,
"answer_choice_id": 2,
"choice_elements": [
{
"data_id": 881,
"data_format_id": 1,
"data_format_value": "data in statement II alone are sufficient to answer the question.",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 2
},
{
"correct_answer": true,
"answer_choice_id": 1,
"choice_elements": [
{
"data_id": 880,
"data_format_id": 1,
"data_format_value": "data in statement I alone are sufficient to answer the question.",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 3
},
{
"correct_answer": false,
"answer_choice_id": 3,
"choice_elements": [
{
"data_id": 882,
"data_format_id": 1,
"data_format_value": "data either in statement I alone or in statement II alone are sufficient to answer the question.",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 4
}
],
"Answer_Choice_Type": "Single Answer",
"score_type": "Item Lvl Score",
"ItemSet_Item_Key": 273,
"yet_to_visit": 0,
"filterCategory": "red",
"mark_for_review": 0,
"not_answered": 1,
"answered": 0,
"answered_marked_for_review": 0,
"seq_no": 1,
"hints_shown": "n",
"user_selected_option": []
},
{
"item_id": 193,
"item_type": 1,
"is_directive": 0,
"directive_content": {},
"hints": "synthesised",
"item": [
{
"data_id": 897,
"data_format_id": 1,
"data_format_value": "Which of the following is the newest element to be discovered and synthesised?",
"item_df_sequence": 1,
"data_identifier": null
},
{
"data_id": 4,
"data_format_id": 11,
"data_format_value": "https://awspikaresources.s3.ap-south-1.amazonaws.com/TenantsDetails/Tech4india2018-06-16/TenantFilesContent/Videos/61e0158cde97a6f2e3a9f3a7c5d81ccf1530684346.mp4",
"item_df_sequence": 2,
"data_identifier": null
}
],
"answer_choices": [
{
"correct_answer": false,
"answer_choice_id": 1,
"choice_elements": [
{
"data_id": 898,
"data_format_id": 1,
"data_format_value": "Flerovium (114)",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 1
},
{
"correct_answer": true,
"answer_choice_id": 4,
"choice_elements": [
{
"data_id": 901,
"data_format_id": 1,
"data_format_value": "Ununseptium (117)",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 2
},
{
"correct_answer": false,
"answer_choice_id": 2,
"choice_elements": [
{
"data_id": 899,
"data_format_id": 1,
"data_format_value": "Ununpentium (115)",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 3
},
{
"correct_answer": false,
"answer_choice_id": 3,
"choice_elements": [
{
"data_id": 900,
"data_format_id": 1,
"data_format_value": "Livermorium (116)",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 4
}
],
"Answer_Choice_Type": "Single Answer",
"score_type": "Item Lvl Score",
"ItemSet_Item_Key": 275,
"yet_to_visit": 1,
"filterCategory": "gray",
"mark_for_review": 0,
"not_answered": 0,
"answered": 0,
"answered_marked_for_review": 0,
"seq_no": 3,
"hints_shown": "n",
"user_selected_option": []
},
{
"item_id": 195,
"item_type": 2,
"is_directive": 0,
"directive_content": {},
"hints": "anti-tetanus ",
"item": [
{
"data_id": 904,
"data_format_id": 1,
"data_format_value": "Blueberries cost more than strawberries",
"item_df_sequence": 1,
"data_identifier": null
},
{
"data_id": 905,
"data_format_id": 1,
"data_format_value": "Blueberries cost less than raspberries.",
"item_df_sequence": 2,
"data_identifier": null
},
{
"data_id": 906,
"data_format_id": 1,
"data_format_value": "Raspberries cost more than strawberries and blueberries",
"item_df_sequence": 3,
"data_identifier": null
},
{
"data_id": 907,
"data_format_id": 1,
"data_format_value": "If the first two statements are true, the third statement is",
"item_df_sequence": 4,
"data_identifier": null
}
],
"answer_choices": [
{
"data_id": 8,
"data_format_id": 1,
"data_format_value": "True",
"answer_choice_id": 1,
"item_df_sequence": 1,
"data_identifier": null,
"correct_answer": true,
"choosed_answer": false,
"seq_id": 1
},
{
"data_id": 9,
"data_format_id": 1,
"data_format_value": "False",
"answer_choice_id": 2,
"item_df_sequence": 2,
"data_identifier": null,
"correct_answer": false,
"choosed_answer": false,
"seq_id": 2
}
],
"Answer_Choice_Type": "Single Answer",
"score_type": "Item Lvl Score",
"ItemSet_Item_Key": 277,
"yet_to_visit": 1,
"filterCategory": "gray",
"mark_for_review": 0,
"not_answered": 0,
"answered": 0,
"answered_marked_for_review": 0,
"seq_no": 4,
"hints_shown": "n",
"user_selected_option": []
},
{
"item_id": 191,
"item_type": 1,
"is_directive": 0,
"directive_content": {},
"hints": "segment",
"item": [
{
"data_id": 884,
"data_format_id": 1,
"data_format_value": "Suppose we have an image given below",
"item_df_sequence": 1,
"data_identifier": null
},
{
"data_id": 7,
"data_format_id": 6,
"data_format_value": "https://awspikaresources.s3.ap-south-1.amazonaws.com/TenantsDetails/Tech4india2018-06-16/TenantFilesContent/Images/87a95c70ae73d23f351b50cddcf459641530684578.jpeg",
"item_df_sequence": 2,
"data_identifier": null
},
{
"data_id": 885,
"data_format_id": 1,
"data_format_value": "Our task is to segment the objects in the image. A simple way to do this is to represent the image in terms of the intensity of pixels and the cluster them according to the values. On doing this, we got this type of structure",
"item_df_sequence": 3,
"data_identifier": null
},
{
"data_id": 8,
"data_format_id": 6,
"data_format_value": "https://awspikaresources.s3.ap-south-1.amazonaws.com/TenantsDetails/Tech4india2018-06-16/TenantFilesContent/Images/04c5c1be6bbfd4f44773e4c68b84c05d1530684594.jpeg",
"item_df_sequence": 4,
"data_identifier": null
},
{
"data_id": 886,
"data_format_id": 1,
"data_format_value": "Suppose we choose k-means clustering to solve the problem, what would be the appropriate value of k from just a visual inspection of the intensity graph?",
"item_df_sequence": 5,
"data_identifier": null
}
],
"answer_choices": [
{
"correct_answer": true,
"answer_choice_id": 3,
"choice_elements": [
{
"data_id": 889,
"data_format_id": 1,
"data_format_value": "3",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 1
},
{
"correct_answer": false,
"answer_choice_id": 1,
"choice_elements": [
{
"data_id": 887,
"data_format_id": 1,
"data_format_value": "1",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 2
},
{
"correct_answer": false,
"answer_choice_id": 2,
"choice_elements": [
{
"data_id": 888,
"data_format_id": 1,
"data_format_value": "2",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 3
},
{
"correct_answer": false,
"answer_choice_id": 4,
"choice_elements": [
{
"data_id": 890,
"data_format_id": 1,
"data_format_value": "4",
"item_df_sequence": 1,
"data_identifier": null
}
],
"choosed_answer": false,
"seq_id": 4
}
],
"Answer_Choice_Type": "Single Answer",
"score_type": "Item Lvl Score",
"ItemSet_Item_Key": 274,
"yet_to_visit": 1,
"filterCategory": "gray",
"mark_for_review": 0,
"not_answered": 0,
"answered": 0,
"answered_marked_for_review": 0,
"seq_no": 5,
"hints_shown": "n",
"user_selected_option": []
}
]
}
]
}
i created pojo also.
my android code given blow. Here i attached my android functions with out pojo. the data print in logcat it not show in the textview
private void fetchTestData() {
JsonObject gsonObject = new JsonObject();
JsonObject paramObject = new JsonObject();
JsonObject current_section = new JsonObject();
paramObject.addProperty("test_id", 30);
paramObject.addProperty("user_id", 23);
paramObject.addProperty("org_id", 1);
paramObject.addProperty("schedule_id", 80);
paramObject.addProperty("next_section_id","");
paramObject.addProperty("group_id", "null");
paramObject.addProperty("current_section", String.valueOf(current_section));
JsonParser jsonParser = new JsonParser();
gsonObject = (JsonObject) jsonParser.parse(paramObject.toString());
retrofit2.Call<Test_Responce> userCall = api_interface.exampleresponce(gsonObject);
userCall.enqueue(new Callback<Test_Responce>() {
#Override
public void onResponse(retrofit2.Call<Test_Responce> call, Response<Test_Responce> response) {
if (response.isSuccessful()){
qnoPalette.clear();
countTimer = response.body().getTimer();
List<ItemsetSection> getItemsetSection = response.body().getItemsetSections();
getSectionAttribute = response.body().getSectionAttributes();
//get Itemset Section
for (int i = 0;i<getItemsetSection.size();i++){
List<SectionItem> getSection = getItemsetSection.get(i).getSectionItems();
for (int j = 0;j<getSection.size();j++){
getItem = getSection.get(j).getItem();
for (int k=0;k<getItem.size();k++){
Const.QuestionSize = getItem.size();
strQuestion.add(getItem.get(k).getDataFormatValue());
}
}
}
for (int i =0; i<getSectionAttribute.size();i++){
txtQuestionPage.setText(Const.currentpage+"/"+getSectionAttribute.get(i).getItemCount());
sectionItem.add( getSectionAttribute.get(i).getSectionName());
Valuesfromserver();
}
Toast.makeText(getApplicationContext(),"success",Toast.LENGTH_SHORT).show();
startCountDownTimer();
}else {
Toast.makeText(getApplicationContext(),"else",Toast.LENGTH_SHORT).show();
}
}
#Override
public void onFailure(retrofit2.Call<Test_Responce> call, Throwable t) {
Toast.makeText(getApplicationContext(),t.getMessage(),Toast.LENGTH_LONG).show();
Log.e("error:",t.getMessage())
; }
});
}
btnQuestion.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
paletteLayout.setVisibility(View.GONE);
txtInst.setVisibility(View.GONE);
for(int i =0;i<strQuestion.size();i++{
textView.setText(strQuestion.get(i);
}
Log.e("questions", String.valueOf(strQuestion));
}
});
it return last question only
Thanks
problem raised in for loop.
i hope this code is useful to you.
for (int i = 0; i <getSection.size();i++){
getItem = getSection.get(i).getItem();
for (int j = 0; j<getItem.size();j++){
Const.QuestionSize = getItem.size();
palette_model = new Palette_Model(getItem.get(j).getDataFormatValue(),
getItem.get(j).getDataFormatId());
strQuestion.add(palette_model);
}
Log.e("val", String.valueOf(strQuestion));
qa.add(String.valueOf(strQuestion));
strQuestion.clear();
}

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.

Categories

Resources