我有一個像這樣使用http包的http請求:
import 'package:http/http.dart' as http;
Uri url = Uri.http(
'http://sample.com',
'/request',
{
'dataMap': {
'key1': ['item1', 'item2']
'key2': ['item1', 'item2']
},
},
);
我收到此錯誤:
_TypeError (type '_InternalLinkedHashMap<String, List<String>>' is not a subtype of type 'Iterable<dynamic>')
如果我沒有在查詢引數中放置地圖,則不會引發錯誤。
那么我該如何發送Map?
uj5u.com熱心網友回復:
你可以jsonEncode地圖:
import 'dart:convert';
void main() {
Uri url = Uri.http(
'sample.com',
'/request',
{
'dataMap': jsonEncode({
'key1': ['item1', 'item2'],
'key2': ['item1', 'item2']
}),
},
);
print(url);
}
uj5u.com熱心網友回復:
您可以通過以下方式實作:
_request() async {
var outer = {};
outer['dataMap'] = {
'key1': ['item1', 'item2'],
'key2': ['item1', 'item2']
};
print(jsonEncode(outer));
return http.post(Uri.parse('https://www.example.com/request'), body: jsonEncode(outer));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/433713.html
上一篇:django-React-Axios:資料未保存在資料庫中
下一篇:如何使用其專案對此進行排序?
