React-Native JSON 从 URL 获取
React-Native JSON fetch from URL
我希望我能找到一些帮助来解决这个问题。
我正在使用 React Native 并尝试从名为 Feiertage-API (https://feiertage-api.de/) 的 API 获取一些数据,基本上 returns(应该return) 德国的法定假日。
尝试在 React Native 中使用 fetch,returns:
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "49C4AD4B-4648-44DB-AED7-7654EB78EF7A",
"name": "api",
"offset": 0,
"size": 487,
"type": "application/json",
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "49C4AD4B-4648-44DB-AED7-7654EB78EF7A",
"name": "api",
"offset": 0,
"size": 487,
"type": "application/json",
},
},
"headers": Headers {
"map": Object {
"access-control-allow-origin": Array [
"*",
],
"content-type": Array [
"application/json",
],
"date": Array [
"Tue, 31 Jul 2018 07:17:51 GMT",
],
"server": Array [
"nginx",
],
"x-powered-by": Array [
"PHP/7.0.31, PleskLin, PleskLin",
],
},
},
"ok": true,
"status": 200,
"statusText": undefined,
"type": "default",
"url": "https://feiertage-api.de/api/?jahr=2019&nur_land=hb",
}
我的提取调用如下所示:
fetch('https://feiertage-api.de/api/?jahr=2019&nur_land=hb')
.then(response => console.log(response) )
.catch(error => console.log(error));
GET 参数是:
- jahr=2019(对于年份,我认为这是显而易见的)
- nur_land=hb(用缩写形式指定什么状态)
通过添加 get-parameter 可以得到 JSONP 'callback=mycallbackname'
如果尝试显示数据:
console.log(response.json())
结果是:
Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
}
我期待看到的正是此处显示的数据 -> https://feiertage-api.de/api/?jahr=2019&nur_land=hb
想知道如何从响应中提取数据{....}。
您需要对该响应调用 .json() 方法。
fetch('https://feiertage-api.de/api/?jahr=2019&nur_land=hb')
.then(response => response.json() )
.then(data => console.log(data) )
.catch(error => console.log(error));
我希望我能找到一些帮助来解决这个问题。
我正在使用 React Native 并尝试从名为 Feiertage-API (https://feiertage-api.de/) 的 API 获取一些数据,基本上 returns(应该return) 德国的法定假日。
尝试在 React Native 中使用 fetch,returns:
Response {
"_bodyBlob": Blob {
"_data": Object {
"blobId": "49C4AD4B-4648-44DB-AED7-7654EB78EF7A",
"name": "api",
"offset": 0,
"size": 487,
"type": "application/json",
},
},
"_bodyInit": Blob {
"_data": Object {
"blobId": "49C4AD4B-4648-44DB-AED7-7654EB78EF7A",
"name": "api",
"offset": 0,
"size": 487,
"type": "application/json",
},
},
"headers": Headers {
"map": Object {
"access-control-allow-origin": Array [
"*",
],
"content-type": Array [
"application/json",
],
"date": Array [
"Tue, 31 Jul 2018 07:17:51 GMT",
],
"server": Array [
"nginx",
],
"x-powered-by": Array [
"PHP/7.0.31, PleskLin, PleskLin",
],
},
},
"ok": true,
"status": 200,
"statusText": undefined,
"type": "default",
"url": "https://feiertage-api.de/api/?jahr=2019&nur_land=hb",
}
我的提取调用如下所示:
fetch('https://feiertage-api.de/api/?jahr=2019&nur_land=hb')
.then(response => console.log(response) )
.catch(error => console.log(error));
GET 参数是: - jahr=2019(对于年份,我认为这是显而易见的) - nur_land=hb(用缩写形式指定什么状态)
通过添加 get-parameter 可以得到 JSONP 'callback=mycallbackname'
如果尝试显示数据: console.log(response.json())
结果是:
Promise {
"_40": 0,
"_55": null,
"_65": 0,
"_72": null,
}
我期待看到的正是此处显示的数据 -> https://feiertage-api.de/api/?jahr=2019&nur_land=hb
想知道如何从响应中提取数据{....}。
您需要对该响应调用 .json() 方法。
fetch('https://feiertage-api.de/api/?jahr=2019&nur_land=hb')
.then(response => response.json() )
.then(data => console.log(data) )
.catch(error => console.log(error));