简体   繁体   中英

Flutter Map or .fromJson of my not working

I have data response with api and i can't map it to List but it return users null, i think is not working because method fromJson

this is data return with api这是API返回的数据

and this is my models来自Json的模型和方法

My controller 在此处输入图像描述

end is Debug window 在此处输入图像描述

Thanks for any answer

Could you further specify what it is that you get as a result? Is the whole list full of null? Or are some of the objects' fields null?

Here is what I believe is an error:

nameUser: json['tenNguoiDung'] == null ? '' : json['ten']
avatarUser: json['nguoiDung_anhDinhKem'] == null ? '' : json['avatar'],

You are saying:

If tenNguoiDung is null: nameUser is equal to '', if it isn't, nameUser = json['ten'].

But your json doesn't have a 'ten' field, so it will be null. What you are most likely looking for is the if-null operator:

nameUser: json['tenNguoiDung'] ?? ''
avatarUser: json['nguoiDung_anhDinhKem'] ?? ''

which will assign '' if the json field is null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM