I'm writing a flutter method in which I want to parse a simple JSON data
{"alm":3,"co2":1,"hu":2,"temp":32,"th":11,"tm":31,"ts":41}
I tried to parse it in a simple get class
List data;
Future<String> getData() async {
http.Response response = await http.get(
Uri.encodeFull("http://chicken20.pythonanywhere.com/jsonn"),
headers: {"Accept": "application/json"});
print(response.body);
data = json.decode(response.body);
print(data);
return "Success!";
and this how I tried to use in material app
body: new ListView.builder(
itemCount: data == null ? 0 : data.length,
itemBuilder: (BuildContext context, int index) {
return new ListTile(
leading: const Icon(Icons.stay_primary_portrait),
title: Text(data.length.toString()),
subtitle:
Text('${_deviceData}'),
trailing: Icon(Icons.more_vert),
dense: true,
isThreeLine: true,
);
},
),
and I got this error
[ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'List<dynamic>'
and nothing was shown in the screen
Mapand you're trying to assign it to aListand use in aListView. What are you trying to accomplish?ListTileand not aListView