I'm working with a RESTful API that seems to be working and used in other applications that gives me something like this:
"notes": [
[
{
"automaticNote": false,
"contactId": 0,
"caseFileId": 0,
"dateCreated": "2019-05-02",
"deletedTime": "2019-05-02T19:31:54.588Z"
}
]
]
The double pair of square brackets means that one pair of the square brackets has no name/key associated with it. To make matters worse, notes is itself nested in some complex JSON.
I tried using JSON to Dart but it throws an error. So really my question is, how do I serialize a JSON array that has no key/name?
I'd normally do it like this:
class Note {
bool automaticNote;
int contactId;
int caseFileId;
String dateCreated;
String deletedTime;
Note(
{this.automaticNote,
this.contactId,
this.caseFileId,
this.dateCreated,
this.deletedTime});
Note.fromJson(Map<String, dynamic> json) {
automaticNote = json['automaticNote'];
contactId = json['contactId'];
caseFileId = json['caseFileId'];
dateCreated = json['dateCreated'];
deletedTime = json['deletedTime'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['automaticNote'] = this.automaticNote;
data['contactId'] = this.contactId;
data['caseFileId'] = this.caseFileId;
data['dateCreated'] = this.dateCreated;
data['deletedTime'] = this.deletedTime;
return data;
}
}
But the double JSON array is throwing me off (and again, notes itself is nested in a more complex JSON object but for the sake of simplicity I did not include the whole thing here).
Thanks!