MAP 和 JSON 格式互转
import "dart:convert";
json.encode(map) // map 转 json
json.decode(json) // json 转 map
Dio 请求接口 第三方
异步方式可用 .then 和 async / await
配置
dependencies:
dio: ^4.0.6
import 'package:dio/dio.dart';
// 获取数据
var response = await Dio().get('https://www.baidu.com',queryParmeters:{'name':"zhangsan"});
print(response.data);
print(response.data is Map);
}
// 提交数据
var response = await Dio().post('https://www.baidu.com',data:{'name':"zhangsan"});
print(response.data);
print(response.data is Map);
}
// 更新数据
var response = await Dio().put('https://www.baidu.com',data:{'name':"zhangsan"});
print(response.data);
print(response.data is Map);
}
// 删除数据
var response = await Dio().delete('https://www.baidu.com',queryParmeters:{'name':"zhangsan"});
print(response.data);
print(response.data is Map);
}