我正在尝试发送http请求与数组列表具有字符串值。
var gameCode = ['1', '2', '3'];
我正在尝试发送以下gameCode
值。
getListOfGames() async {
try {
print(gameCode);
'http://localhost:8232',
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(
<String, dynamic>{
'game_code': gameCode,
},
),
);
}
然而,我得到这个Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<String>'
错误。当我只发送空[]
,然后它工作。所以,我认为这与类型有关。我需要将List<String>
转换为List<dynamic>
或类似的东西。
我如何将gameCode
列表更改为List<dynamic>
,以便我可以将其包含到我的http.post
请求中?
List<dynamic> gameCode = ['1', '2', '3'];
// ...
body: jsonEncode({
'game_code': gameCode,
},),