json - Flutter:JSON响应不完整
问题描述
我正在尝试从 Flutter 中的 API 获取每周的股票数据。但是,响应很早就被切断了。我错过了什么?
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);
}
print(resp.body.toString());
List<StockWeek> list = new List<StockWeek>();
// parse JSON
return list;
}
我在打印声明时得到的是:
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&symbol=MSFT&apikey=demo
解决方案
print()
当使用很多行时,这只是一个日志记录问题。按照这里的推荐使用debugPrint()
Flutter 的foundation
库。
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;
}
推荐阅读
- python - 为什么当我在“os.popen()”对象上使用“dir”内置函数时没有出现“read”方法?
- django - django 项目总是尝试(并且失败)在单独的应用程序中加载文件
- android - 隐式深层链接无法正常工作 - onCreate 调用了两次
- javascript - 如何将对象附加到 JSON 文件(涉及:JavaScript、Discord.js 和 JSON)
- node.js - 如何将对象保存到自定义集合?
- opencv - 系统错误:
返回带有错误集的结果 - git - 重新排序本地提交
- python - 将整数旋转到固定位数
- html - ALT 文本未显示在 Outlook、Yahoo 等主要电子邮件客户端上
- java - 如何在 Java 中打开 LMDB 数据库?