Reputation: 585
I have to Store Every Element of List to List so how i can do this?
Json Response as below.
{
"responseCode": 200,
"responseMessage": "OK",
"data": null,
"dataList": [
"Technical",
"Field"
],
"excelDataList": null,
"totalRecords": 2,
"pageRecords": 0,
"currentPageNumber": 1,
"totalPages": 0
}
Here i have to store dataList values in list.
Upvotes: 1
Views: 1021
Reputation: 172
You first have to call jsonDecode
to convert your String into deserialized data, then you can use the []
operator to access individual keys.
import "dart:convert";
const String apiResult = """{
"responseCode": 200,
"responseMessage": "OK",
"data": null,
"dataList": [
"Technical",
"Field"
],
"excelDataList": null,
"totalRecords": 2,
"pageRecords": 0,
"currentPageNumber": 1,
"totalPages": 0
}
""";
void main() {
Map<String, dynamic> des = jsonDecode(apiResult);
List<dynamic> data = des["dataList"];
print(data);
}
which would print
> [Technical, Field]
Upvotes: 1