I/flutter (19224): {
I/flutter (19224): "Meta Data": {
I/flutter (19224): "1. Information": "Weekly Prices (open, high, low, close) and Volumes",
I/flutter (19224): "2. Symbol": "MSFT",
I/flutter (19224): "3. Last Refreshed": "2018-12-03",
I/flutter (19224): "4. Time Zone": "US/Eastern"
I/flutter (19224): },
I/flutter (19224): "Weekly Time Series": {
I/flutter (19224): "2018-12-03": {
I/flutter (19224): "1. open": "113.0000",
I/flutter (19224): "2. high": "113.4200",
I/flutter (19224): "3. low": "110.7300",
I/flutter (19224): "4. close": "112.0900",
I/flutter (19224): "5. volume": "34275048"
I/flutter (19224): },
I/flutter (19224): "2018-11-30": {
I/flutter (19224): "1. open": "104.7900",
I/flutter (19224): "2. high": "111.3300",
I/flutter (19224): "3. low": "104.5800",
I/flutter (19224): "4. close": "110.8900",
I/flutter (19224): "5. volume": "170037931"
I/flutter (19224): },
I/flutter (19224): "2018-11-23": {
I/flutter (19224): "1. open": "108.2700",
I/flutter (19224): "2. high": "108.5600",
I/flutter (19224): "3. low": "99.3528",
I/flutter (19224): "4. close": "103.0700",
I/flutter (19224): "5. volume": "150780076"
I/flutter (19224): },
I/flutter (19224): "2018-11-16": {
I/flutter (19224): "1. open": "109.4200",
I/flutter (19224): "2. high": "109.9600",
I/flutter (19224): "3. low": "103.9100",
I/flutter (19224): "4.
在这一点上始终停止。 而不是答复应该是什么样的:
https://www.alphavantage.co/query?function = time_series_weekly&symble = msft&apikey =demo
库中的
库。
foundation
没什么可担心的。只是,如果打印数据的输出太大,则只有数据的某些部分将显示在控制台中。我试图找出原因,但仍然没有找到任何原因。但是,当您在构建屏幕时尝试使用它时,您将获取您想要的所有数据。所以我的底线:只需构建您的小部件(屏幕布局)并按照您的需求使用数据,它将奏效。 ,例如,我使用了此Https://jsonplaceholder.typicode.com/posts作为我的JSON数据源
创建一个称为网络的类:
import 'package:flutter/foundation.dart';
static Future<List<StockWeek>> fetchAll() async {
// creates: https://www.alphavantage.co/query?function=TIME_SERIES_WEEKLY&symbol=MSFT&apikey=demo
var uri = Endpoint.uri('', queryParameters: { "function" : "TIME_SERIES_WEEKLY", "symbol" : "MSFT", "apikey" : "demo" });
final resp = await http.get(uri.toString());
if (resp.statusCode != 200) {
throw (resp.body);
}
debugPrint(resp.body.toString());
List<StockWeek> list = new List<StockWeek>();
// parse JSON
return list;
}
这是用于显示所获取内容的屏幕:
import 'dart:convert';
import 'package:http/http.dart' as http;
class Networking {
final String url;
Networking({this.url});
Future getNewsData() async {
http.Response response = await http.get(url);
if (response.statusCode == 200) {
String data = response.body;
return jsonDecode(data);
} else {
print(response.statusCode);
}
}
}
显示屏的napshot
我遇到了同样的问题,并且确实遇到了困难,因为我在打印时遇到了一个错误解码和一个不完整的字符串,所以我认为我没有收到整个通信。我看到了这篇文章的答案,说使用“ debugprint”,但我仍然有一个不完整的字符串,所以它确实使我陷入了错误的方向。 我的字符串完成了,但是如果有人在同一问题上挣扎,debugprint也不完全显示出来。