Json 颤振-使用API键
我正在制作一个应用程序,可以从中获取加密货币JSON数据,但对此的支持很快就会被放弃,这意味着我必须迁移更强大的 唯一的问题是,我不知道如何使用解析JSON数据时所需的新Api键 我正在使用一个经过大量修改的版本来编程这个应用程序,但是所有的基本功能都是基于这里的 所有我需要的是什么,我需要添加到这个文件来显示新的专业v1api的指导,任何意见或想法表示感谢。谢谢 这是Json 颤振-使用API键,json,dart,flutter,restful-authentication,restful-url,Json,Dart,Flutter,Restful Authentication,Restful Url,我正在制作一个应用程序,可以从中获取加密货币JSON数据,但对此的支持很快就会被放弃,这意味着我必须迁移更强大的 唯一的问题是,我不知道如何使用解析JSON数据时所需的新Api键 我正在使用一个经过大量修改的版本来编程这个应用程序,但是所有的基本功能都是基于这里的 所有我需要的是什么,我需要添加到这个文件来显示新的专业v1api的指导,任何意见或想法表示感谢。谢谢 这是crypto_data_prod.dart文件,在该文件中,我必须更改代码以与密钥一起使用 import 'dart:async
crypto_data_prod.dart
文件,在该文件中,我必须更改代码以与密钥一起使用
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import 'package:fluttercrypto/data/crypto_data.dart';
class ProdCryptoRepository implements CryptoRepository {
String cryptoUrl = "https://api.coinmarketcap.com/v1/ticker/?limit=50";
@override
Future<List<Crypto>> fetchCurrencies() async {
// TODO: implement fetchCurrencies
http.Response response = await http.get(cryptoUrl);
final List responseBody = JSON.decode(response.body);
final statusCode = response.statusCode;
if (statusCode != 200 || responseBody == null) {
throw new FetchDataException(
"An error ocurred : [Status Code : $statusCode]");
}
return responseBody.map((c) => new Crypto.fromMap(c)).toList();
}
}
导入'dart:async';
导入“dart:convert”;
将“package:http/http.dart”导入为http;
导入“包:flattercrypto/data/crypto_data.dart”;
类ProdCryptoRepository实现CryptoRepository{
字符串加密URL=”https://api.coinmarketcap.com/v1/ticker/?limit=50";
@凌驾
Future fetch()异步{
//TODO:实现抓取
http.Response-Response=wait-http.get(cryptoUrl);
最终列表responseBody=JSON.decode(response.body);
最终状态代码=response.statusCode;
if(statusCode!=200 | | responseBody==null){
抛出新的FetchDataException(
“出现错误:[状态代码:$statusCode]”;
}
返回responseBody.map((c)=>newcrypto.fromMap(c)).toList();
}
}
尝试更改http.Response-Response=wait-http.get(cryptoUrl)代码>到
http.Response-Response=wait http.get(cryptoUrl,
标题:{“X-CMC PRO_API_密钥”:“cab79c7b-52e9-4e4b-94fc-b0f32da14799”})代码>
查看更多信息。我确信这是可行的,但事实证明JSON类型的样式与公共V1 api不同,我现在得到的错误是type'\u InternalLinkedHashMap'不是type'List'的子类型。
Hi danil,这方面有什么好运气吗?