How do you serialize/parse a nested JSON array in Flutter/Dart if it has no name/key
After decoding, notes
is a member of some Map<String, dynamic>
as usual. Let's call that m
.
So m['notes']
is a list, who's first member, m['notes'][0]
is also a list. Its first member, m['notes'][0][0]
is another Map<String, dynamic>
, which is what you need for your constructor.
You should therefore be able to use:
Note n = Note.fromJson(m['notes'][0][0]);
Let's take the case of you saving automaticNote;
automaticNote = json['notes'][0][0]['automaticNote'];
This offers the key for notes which has an array where your data is at the first point or index 0 (of notes hence [0]) and within that array there is another array which has your data. Again it's the first array item so, [0] and then you're finally at the level with your data so you then use your key for automaticNote, ['automaticNote'].
Note.fromJson(Map<String, dynamic> json) { automaticNote = json[0][0]['automaticNote']; contactId = json[0][0]['contactId']; caseFileId = json[0][0]['caseFileId']; dateCreated = json[0][0]['dateCreated']; deletedTime = json[0][0]['deletedTime']; }