I have implemented code to store the JSON data returned to be stored in local DB (SQFlite).
I want to store only those data where the is_deleted
parameter is 0.
I am not sure how to implement that. Any solution will be of great help.
This is the JSON :
"subject": [
{
"univ_spec_sub_id": "53",
"univ_year_sem_id": "18",
"sem_id": "2",
"university_id": "5",
"master_course_id": "36",
"subject_name": "Programming and Problem Solving",
"subject_desc": "99",
"info": "Programming and Problem Solving using Python",
"no_units": "6",
"is_deleted": "0",
},
{
"univ_spec_sub_id": "59",
"univ_year_sem_id": "18",
"sem_id": "2",
"university_id": "5",
"master_course_id": "37",
"subject_name": "Basic Electrical Engineering",
"subject_desc": "99",
"info": "",
"no_units": "100",
"is_deleted": "0",
},
{
"univ_spec_sub_id": "61",
"univ_year_sem_id": "18",
"sem_id": "2",
"university_id": "5",
"master_course_id": "38",
"subject_name": "Engineering Mathematics II",
"subject_desc": "99",
"info": "",
"no_units": "6",
"is_deleted": "0",
},
{
"univ_spec_sub_id": "65",
"univ_year_sem_id": "18",
"sem_id": "2",
"university_id": "5",
"master_course_id": "39",
"subject_name": "Engineering Graphics",
"subject_desc": "99",
"info": "",
"no_units": "6",
"is_deleted": "1",
}
],
I have implemented the following code to store the JSON returned into local DB.
Future<Semdata> semdata(String url, {Map body} ) {
return http.post(url,
body:body).then((http.Response response){
if (response.statusCode < 200 || response.statusCode > 400 || json == null) {
throw new Exception("Error while fetching data");
}
//JsonDecoder().convert(response.body);
var extractdata = json.decode(response.body);
List subdata = extractdata["subject"];
Map<String, dynamic> decodedData = json.decode(response.body);
for(Map<String, dynamic> subjectMap in decodedData['subject']){
print(subjectMap["subject"]["is_deleted"]);
if(subjectMap["subject"]["is_deleted"]== "0"){
db.savesubject(subjectMap);
}
// db.savesubject(subjectMap);
}
return Semdata.fromJson(json.decode(response.body));
});
}