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();
}
Related
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 execute and get the output of the FFMProbe command on FFMPegKit? I tried various ways. But I failed. Can anyone help me, please?
After a few days later I got success (though the Question and answer time is same. But I tried it earlier more).
FFprobeKit.executeAsync("-v error -show_streams -print_format json videopath") { session ->
Log.d("TAG", "fileDetails: FMProbe output: ${session?.output}")
}
This Log.d print the details of inputted video as a JSON (as the command).
FFMProbe output: {
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "unknown",
"profile": "100",
"codec_type": "video",
"codec_time_base": "1/60",
"codec_tag_string": "avc1",
"codec_tag": "0x31637661",
"width": 1920,
"height": 1080,
"coded_width": 1920,
"coded_height": 1088,
"closed_captions": 0,
"has_b_frames": 1,
"sample_aspect_ratio": "1:1",
"display_aspect_ratio": "16:9",
"pix_fmt": "yuv420p",
"level": 40,
"color_range": "tv",
"color_space": "bt709",
"color_transfer": "bt709",
"color_primaries": "bt709",
"chroma_location": "left",
"refs": 1,
"is_avc": "true",
"nal_length_size": "4",
"r_frame_rate": "30/1",
"avg_frame_rate": "30/1",
"time_base": "1/15360",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 3329024,
"duration": "216.733333",
"bit_rate": "1461827",
"bits_per_raw_sample": "8",
"nb_frames": "6502",
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"language": "und",
"handler_name": "ISO Media file produced by Google Inc.",
"vendor_id": "[0][0][0][0]"
}
},
{
"index": 1,
"codec_name": "aac",
"codec_long_name": "unknown",
"profile": "1",
"codec_type": "audio",
"codec_time_base": "1/44100",
"codec_tag_string": "mp4a",
"codec_tag": "0x6134706d",
"sample_fmt": "fltp",
"sample_rate": "44100",
"channels": 2,
"channel_layout": "stereo",
"bits_per_sample": 0,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/44100",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 9561088,
"duration": "216.804717",
"bit_rate": "127999",
"max_bit_rate": "127999",
"nb_frames": "9337",
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"language": "und",
"handler_name": "ISO Media file produced by Google Inc.",
"vendor_id": "[0][0][0][0]"
}
}
]
}
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');
}
}
{
"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)
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.