在写这个问题之前,我看了以下链接:
守则:
List data = [
{
"title" : "Particulate matter",
"desc" : "The term used to describe a mixture of solid particles and liquid droplets found in the air",
"amt" : 500,
"diseases" : "Particulate matter is responsible for asthma in many people. Also, a topic dermatitis, allergic rhinitisare diseases that can be caused by this",
"precaution" : "Switching to cleaner appliances and reducing the amount of smoking will surely ensure less exposureof particulate matter in the environment",
"image" : 'https://images.pexels.com/photos/3668372/pexels-photo-3668372.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
"color" : Color(0xFF6E7E5D).withOpacity(.3)
},
// loads of data in this structure
];
// the line of error
Map indexedData = Map<String, dynamic>.from(data[index]);
我只是不知道为什么错误存在,所以请帮帮我。谢谢你!
编辑:如果有助于解决问题,我可以将数据更改为限制
您应该这样声明类型:
Map<String, dynamic> indexedData = Map<String, dynamic>.from(data[index]);
List data = [
{
"title": "Particulate matter",
"desc":
"The term used to describe a mixture of solid particles and liquid droplets found in the air",
"amt": 500,
"diseases":
"Particulate matter is responsible for asthma in many people. Also, a topic dermatitis, allergic rhinitisare diseases that can be caused by this",
"precaution":
"Switching to cleaner appliances and reducing the amount of smoking will surely ensure less exposureof particulate matter in the environment",
"image":
'https://images.pexels.com/photos/3668372/pexels-photo-3668372.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260',
"color": Color(0xFF6E7E5D).withOpacity(.3),
},
];
Map<String, dynamic> indexedData = {};
data.forEach((mapElement) {
Map map = mapElement as Map;
map.forEach((key, value) {
indexedData[key] = value;
});
});
print(indexedData);
我是颤振初学者。我得到这样的JSON响应时出错。 我一直在论坛上寻找这个问题,我发现是这样的。 但我不懂如何编写函数。这是我的密码。 还有像这样的错误。 我很抱歉问了同样的问题,因为我不明白
我有点被某些情况困住了。 1)
在存储到本地数据库之前,将字符串转换为对象的正确方法是什么? 这是的输出: 我试图将其转换为CreatedBy对象 创造的 这里是我的本地表列 错误
如果flatter中存在列表,是否会处理列表映射? 在上面的类中,我们需要手动将json转换为电影列表吗?
这是我的代码: 我得到的错误是: _类型错误(类型“\u InternalLinkedHashMap
我有错误从标题时试图这样做 > 我创建了@JsonSerialiazable()类来处理json 然后,在调用http时。get(),我执行以下操作: map变量如下所示: 当调用$MyResponseFromJson(json)时,当它试图从我的响应中执行(json['a']as List)时,它会给出一个错误。g、 构建运行程序生成的dart文件。 我如何修复错误? 谢啦