I want submit Selected answers array how can do this.
How to pass selected answer in this array
2
Flutter/Dart doesn’t have arrays. Use lists instead.
In the api-response ,it’s always formatted into either List of Map or Map of List.
List of Map is Like :
[ { "name":"ruby", "gender":"female" }, { "name":"otis", "gender":"male" }, ]
And, Map of List is Like :
{ "data": [ "Professor", "Berlin", "Tokyo" ] }
So to access them you have to use JsonDecode and then look the response and process that.
For Map response ….
var resMap = jsonDecode(response.body);
For List response (use key after resMap with key)…
var resMap = jsonDecode(response.body); var infoList = resMap["data"];
class CatTypeController { Future<void> getLeaves() async { String url = "https://meowfacts.herokuapp.com/?count=2"; http.Response response = await http.get(Uri.parse(url)); if (response.statusCode == 200) { Map rM = jsonDecode(response.body); print(rM["data"]); } } }
["In ancient Egypt, killing a cat was a crime punishable by death.","The way you treat kittens in the early stages of it's life will render it's personality traits later in life."]
Click here to cancel reply.
2
Answers
Flutter/Dart doesn’t have arrays. Use lists instead.
Solution
In the api-response ,it’s always formatted into either List of Map or Map of List.
List of Map is Like :
And, Map of List is Like :
So to access them you have to use JsonDecode and then look the response and process that.
For Map response ….
For List response (use key after resMap with key)…
Demo
Response
Output