回答編集履歴
2
chuosei
test
CHANGED
@@ -25,3 +25,27 @@
|
|
25
25
|
test3();
|
26
26
|
|
27
27
|
```
|
28
|
+
|
29
|
+
もしくは
|
30
|
+
|
31
|
+
```javascript
|
32
|
+
|
33
|
+
const url = 'https://www.jma.go.jp/bosai/forecast/data/overview_week/130000.json';
|
34
|
+
|
35
|
+
const test2 = () => {
|
36
|
+
|
37
|
+
fetch(url).then(async res=>({json:await res.json().then(data=>data)})).then(data=>console.log(data.json));
|
38
|
+
|
39
|
+
};
|
40
|
+
|
41
|
+
test2();
|
42
|
+
|
43
|
+
const test3 = () => {
|
44
|
+
|
45
|
+
fetch(url).then(async res=>[await res.json().then(data=>data)]).then(data=>console.log(data[0]));
|
46
|
+
|
47
|
+
};
|
48
|
+
|
49
|
+
test3();
|
50
|
+
|
51
|
+
```
|
1
chouse
test
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
json()自体がpromiseを返すのでthenで受ければ値をとれますが
|
2
|
+
|
3
|
+
[json()]はpromiseが入った配列を返すので、thenで受けても値は取り出せません
|
4
|
+
|
5
|
+
|
6
|
+
|
1
7
|
```javascript
|
2
8
|
|
3
9
|
const url = 'https://www.jma.go.jp/bosai/forecast/data/overview_week/130000.json';
|