问题
I am developing a Flutter app and I am getting a JSON data like below
{chat_mode: supplier, timestamp: 1605852885271, last_message: Test, members: [K9ioYyiEUQVVNjx0owwsABCD, K9ioYyiEUQVVNjx0owwsaXYZ]}
I need to access each individual element under members
and this is what I tried.
Map<dynamic, dynamic> map = snapshot.value;
print(map["members"]);
The above allows me to access the entire array, not each record.
But i can't access the individual element by using something like map["members"][0]
because it is a map. In this case, how can i access this data?
回答1:
You have to explicitly convert it to a List
try
List<dynamic> members = List.of(map["members"]);
or
List<dynamic> members = map["members"];
来源:https://stackoverflow.com/questions/64927867/flutter-how-to-access-array-data-inside-a-map