我可以从HttpClientResponse返回json列表吗?

问题描述 投票:0回答:1

我正在尝试使用dart和flutter连接我们的服务器。我在证书服务器中收到错误,我得到了代码并且我得到了完全的响应,但问题是响应一直以字符串形式返回。我希望它作为循环它的列表。

HttpClient client = new HttpClient();
client.badCertificateCallback =((X509Certificate cert, String host, int port) => true);
String url ='https://xxx';
//Map map = { "email" : "email" , "password" : "password"};
HttpClientRequest request = await client.getUrl(Uri.parse(url));
//request.headers.set('content-type', 'application/json');
//request.add(utf8.encode(json.encode(map)));
HttpClientResponse response = await request.close();
String reply = await response.transform(utf8.decoder).join();
print(reply);

我有简单的代码来获取JSON响应作为列表。问题是我们的服务器使用https和nginx将所有请求带到正确的端口。以前的代码工作,但我需要回复一个列表。

简单的代码是:

String apiURL = "https://jsonplaceholder.typicode.com/posts";

 http.Response response = await http.get(apiURL);

return json.decode(response.body);
dart flutter
1个回答
0
投票

你不会得到一份清单。你会得到你需要处理的扁平json。可以使用PowerShell使用简单脚本完成处理。

© www.soinside.com 2019 - 2024. All rights reserved.