我打算在initState函数里面写API获取JSON数据的函数,通过listView组件来展示,结果第一次运行是显示
Null check operator used on a null value
接着我点击AS编译器左下角的⚡符号,然后就可以展示页面了,请问这是什么原因
以下是代码
void initState(){
super.initState();
tiantianjijin(); //这个是请求API接口数据的函数
}
以及API获取JSON函数,这个我和主程序放在同个代码文件
tiantianjijin() async{
var headers = {
'Accept': '*/*',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Cookie': 'st_si=23513143112904; st_asi=delete; st_pvi=75677265749136; st_sp=2022-08-30%2014%3A49%3A55; st_inirUrl=https%3A%2F%2Fwww.nowcoder.com%2F; st_sn=4; st_psi=20230303151428570-112200312935-2690096899',
'Proxy-Connection': 'keep-alive',
'Referer': 'http://fund.eastmoney.com/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.57',
'Accept-Encoding': 'gzip',
};
http://api.fund.eastmoney.com/FundGuZhi/GetFundGZList?type=1&sort=3&orderType=desc&canbuy=1&pageIndex=1&pageSize=200&callback=jQuery1830052794852709326934_1677850528473&_=1677850531737
var url = Uri.parse('http://api.fund.eastmoney.com/FundGuZhi/GetFundGZList?type=1&sort=3&orderType=desc&canbuy=1&pageIndex=1&pageSize=200');
var res = await http.get(url, headers: headers);
if (res.statusCode != 200) throw Exception('http.get error: statusCode= ${res.statusCode}');
t = Tiantianjijin.fromJson(jsonDecode(res.body));
for (var element in t!.data!.list!) { print("${element.bzdm}");}
}