【发布时间】:2020-05-14 07:14:17
【问题描述】:
我的函数如下所示:
async function getPlaceForecast(lat, long) {
//var response;
var day5forecast = 'http://api.openweathermap.org/data/2.5/forecast?lat=' + lat + '&lon=' + long + '&appid=' + apikey;
try {
const request = new Request(tmp2, {
method: 'get'
})
let response = await fetch(request)
.then(value => {
console.log("than", value.json());
return value//.json();
})
.catch(function (error) {
console.error(error);
});
}
catch{
}
//return response;
}
这是结果:
'than', { _40: 0, _65: 0, _55: null, _72: null }
这是不使用 .json() 的结果:
'than', { type: 'default',
status: 200,
ok: true,
statusText: undefined,
headers:
{ map:
{ 'access-control-allow-methods': 'GET, POST',
'access-control-allow-credentials': 'true',
'access-control-allow-origin': '*',
'x-cache-key': '/data/2.5/forecast?lat=28.35&lon=-14.05',
connection: 'keep-alive',
'content-length': '14383',
'content-type': 'application/json; charset=utf-8',
server: 'openresty' } },
url: 'http://api.openweathermap.org/data/2.5/forecast?lat=28.349414&lon=-14.046311&appid=<mykey>',
_bodyInit:
{ _data:
{ size: 14383,
offset: 0,
blobId: '2dbf82c5-5d28-47db-9034-7f239bf8290a' } },
_bodyBlob:
{ _data:
{ size: 14383,
offset: 0,
blobId: '2dbf82c5-5d28-47db-9034-7f239bf8290a' } } }
我做错了什么?
【问题讨论】:
-
url变量“day5forecast”在哪里使用?
标签: javascript android ios react-native request