I am trying to parse a JSON array to a List in my app, it worked with other model classes but I getting the error with this particular one only. I have used similar codes in other cases it worked but it's not working here. If you use just List instead of changing the type to the model class and initiate the response it works.
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
Class 'StudyList' has no instance method '[]'.
Receiver: Instance of 'StudyList'
Tried calling: []("reportStatus")
════════════════════════════════════════════════════════════════════════════════════════════════════
This is my model class:
class StudyList {
String studyUID;
String patientId;
String patientName;
String studyDateTime;
String modalityName;
String study;
String studyDescription;
String refferringPhysician;
String clinicalHistory;
String siteName;
String reportPath;
String attachmentPath;
String imageReceviedTime;
var reportReceviedTime;
int noOfImages;
String reportStatus;
String radiologistName;
String gender;
String age;
int series;
int siteID;
int radiologistID;
var reportReceviedTime1;
String radiologistAssignedTime;
int radcentreId;
String examdate;
int emergencyst;
String studycode;
var repdown;
String thumbnail;
int modality;
int status;
var studyview;
var studydown;
StudyList(
{this.studyUID,
this.patientId,
this.patientName,
this.studyDateTime,
this.modalityName,
this.study,
this.studyDescription,
this.refferringPhysician,
this.clinicalHistory,
this.siteName,
this.reportPath,
this.attachmentPath,
this.imageReceviedTime,
this.reportReceviedTime,
this.noOfImages,
this.reportStatus,
this.radiologistName,
this.gender,
this.age,
this.series,
this.siteID,
this.radiologistID,
this.reportReceviedTime1,
this.radiologistAssignedTime,
this.radcentreId,
this.examdate,
this.emergencyst,
this.studycode,
this.repdown,
this.thumbnail,
this.modality,
this.status,
this.studyview,
this.studydown});
StudyList.fromJson(Map<String, dynamic> json) {
studyUID = json['studyUID'];
patientId = json['patientId'];
patientName = json['patientName'];
studyDateTime = json['studyDateTime'];
modalityName = json['modalityName'];
study = json['study'];
studyDescription = json['studyDescription'];
refferringPhysician = json['refferringPhysician'];
clinicalHistory = json['clinicalHistory'];
siteName = json['siteName'];
reportPath = json['reportPath'];
attachmentPath = json['attachmentPath'];
imageReceviedTime = json['imageReceviedTime'];
reportReceviedTime = json['reportReceviedTime'];
noOfImages = json['noOfImages'];
reportStatus = json['reportStatus'];
radiologistName = json['radiologistName'];
gender = json['gender'];
age = json['age'];
series = json['series'];
siteID = json['siteID'];
radiologistID = json['radiologistID'];
reportReceviedTime1 = json['reportReceviedTime1'];
radiologistAssignedTime = json['radiologistAssignedTime'];
radcentreId = json['radcentreId'];
examdate = json['examdate'];
emergencyst = json['emergencyst'];
studycode = json['studycode'];
repdown = json['repdown'];
thumbnail = json['thumbnail'];
modality = json['modality'];
status = json['status'];
studyview = json['studyview'];
studydown = json['studydown'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['studyUID'] = this.studyUID;
data['patientId'] = this.patientId;
data['patientName'] = this.patientName;
data['studyDateTime'] = this.studyDateTime;
data['modalityName'] = this.modalityName;
data['study'] = this.study;
data['studyDescription'] = this.studyDescription;
data['refferringPhysician'] = this.refferringPhysician;
data['clinicalHistory'] = this.clinicalHistory;
data['siteName'] = this.siteName;
data['reportPath'] = this.reportPath;
data['attachmentPath'] = this.attachmentPath;
data['imageReceviedTime'] = this.imageReceviedTime;
data['reportReceviedTime'] = this.reportReceviedTime;
data['noOfImages'] = this.noOfImages;
data['reportStatus'] = this.reportStatus;
data['radiologistName'] = this.radiologistName;
data['gender'] = this.gender;
data['age'] = this.age;
data['series'] = this.series;
data['siteID'] = this.siteID;
data['radiologistID'] = this.radiologistID;
data['reportReceviedTime1'] = this.reportReceviedTime1;
data['radiologistAssignedTime'] = this.radiologistAssignedTime;
data['radcentreId'] = this.radcentreId;
data['examdate'] = this.examdate;
data['emergencyst'] = this.emergencyst;
data['studycode'] = this.studycode;
data['repdown'] = this.repdown;
data['thumbnail'] = this.thumbnail;
data['modality'] = this.modality;
data['status'] = this.status;
data['studyview'] = this.studyview;
data['studydown'] = this.studydown;
return data;
}
}
This is my code for parsing the data from the API:
List<StudyList> _patientDataapi = List();
setState(() {
_shimmerLoader = true;
_patientDataapi = (json.decode(res.body))
.map<StudyList>((item) => StudyList.fromJson(item))
.toList();
});
And lastly, this is the JSON data being fetched while making API:
[
{
"studyUID": "1.2.840.113619.2.55.3.2831168001.314.1602949790.991",
"patientId": "4789",
"patientName": "MR.ANIKET ADKAKE",
"studyDateTime": "2020-10-17T22:22:04",
"modalityName": "CT",
"study": "NECK PLAIN",
"studyDescription": "CT-NECK",
"refferringPhysician": "G.H.S",
"clinicalHistory": "H/O- LOSS OF VOICE",
"siteName": "Aditya sangli",
"reportPath": "",
"attachmentPath": "",
"imageReceviedTime": "2020-10-17T22:24:49",
"reportReceviedTime": null,
"noOfImages": 215,
"reportStatus": "Pending",
"radiologistName": "Dr.Agarwal",
"gender": "M",
"age": "026Y",
"series": 5,
"siteID": 209,
"radiologistID": 518,
"reportReceviedTime1": null,
"radiologistAssignedTime": "2020-10-17T22:48:00",
"radcentreId": 6,
"examdate": "2020-10-17T21:38:57",
"emergencyst": 0,
"studycode": "CT-21",
"repdown": null,
"thumbnail": "",
"modality": 1,
"status": 3,
"studyview": null,
"studydown": null
},
{
"studyUID": "1.2.840.113619.2.55.3.2831168001.314.1602949791.126",
"patientId": "CT-4792",
"patientName": "MR.ANIKET ADAKE",
"studyDateTime": "2020-10-17T23:49:32",
"modalityName": "CT",
"study": "NECK PLAIN",
"studyDescription": "CT-NECK PLAIN",
"refferringPhysician": "G.H.S",
"clinicalHistory": "H/O- LOSS OF VOICE",
"siteName": "Aditya sangli",
"reportPath": "C:\\KINSOLUTIONS\\Team\\Report\\1.2.840.113619.2.55.3.2831168001.314.1602949791.126.docx",
"attachmentPath": "",
"imageReceviedTime": "2020-10-17T23:50:29",
"reportReceviedTime": null,
"noOfImages": 273,
"reportStatus": "Final",
"radiologistName": "Dr.Agarwal",
"gender": "M",
"age": "025Y",
"series": 4,
"siteID": 209,
"radiologistID": 518,
"reportReceviedTime1": "2020-10-18T00:25:07",
"radiologistAssignedTime": "2020-10-17T23:52:08",
"radcentreId": 6,
"examdate": "2020-10-17T23:46:03",
"emergencyst": 0,
"studycode": "CT-21",
"repdown": true,
"thumbnail": "",
"modality": 1,
"status": 5,
"studyview": null,
"studydown": null
}
]