I have an error when trying to parse my JSON and display it in the text, not as a listview.
Below is my JSON structure.
{
"status": "success",
"data": {
"id": 5,
"name": afri,
"class": 3c'
},
"message": "Success"
}
and this is my Future API async.
Future<Map> getData() async {
var response = await http.get(
'url');
return json.decode(response.body) as Map<String, dynamic>;
}
and this is my code to display the JSON.
Container(
child: FutureBuilder<Map>(
future: getData(),
builder: (context, snapshot) {
Map<String, dynamic> data = jsonDecode(snapshot.data["data"]);
return Card(
child: Container(
padding: EdgeInsets.all(8),
color: Colors.red,
child: Text(
data['port_website'],
style: TextStyle(color: Colors.white, fontSize: 24),
),
),
);
},
),
),
and when I'm trying to get the data, I got an error like this.
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'
which code should I fix?
Map<String, dynamic> data = jsonDecode(snapshot.data["data"]);with thisList<dynamic> data = jsonDecode(snapshot.data["data"]);- E. Shcherbo