回答編集履歴
2
テキスト修正
answer
CHANGED
@@ -1,16 +1,29 @@
|
|
1
1
|
こんにちは
|
2
2
|
|
3
|
+
JSONが返ってきているので、`response.text()` を `response.json()` とすればよいかと思います。
|
3
|
-
以下のように修正してみると、いかがでしょうか?
|
4
|
+
ですので、以下のように修正してみると、いかがでしょうか?
|
4
5
|
|
5
6
|
|
6
7
|
**修正前:**
|
7
8
|
```javascript
|
9
|
+
fetch('https://opentdb.com/api.php?amount=10')
|
8
|
-
response => response.text()
|
10
|
+
.then(response => response.text())
|
11
|
+
.then(text => {
|
12
|
+
console.log(text);
|
13
|
+
console.log(text.results);
|
14
|
+
console.log(text.results[0].question);
|
15
|
+
});
|
9
16
|
```
|
10
17
|
|
11
18
|
**修正後:**
|
12
19
|
```javascript
|
20
|
+
fetch('https://opentdb.com/api.php?amount=10')
|
13
|
-
response => response.json()
|
21
|
+
.then(response => response.json())
|
22
|
+
.then(json => {
|
23
|
+
console.log(json);
|
24
|
+
console.log(json.results);
|
25
|
+
console.log(json.results[0].question);
|
26
|
+
});
|
14
27
|
```
|
15
28
|
|
16
29
|
以下、動作確認するために修正後のコードを jsFiddle に上げたものです。
|
1
テキスト修正
answer
CHANGED
@@ -13,9 +13,9 @@
|
|
13
13
|
response => response.json()
|
14
14
|
```
|
15
15
|
|
16
|
-
以下、修正後のコードを jsFiddle に上げたものです。
|
16
|
+
以下、動作確認するために修正後のコードを jsFiddle に上げたものです。
|
17
17
|
|
18
|
-
- [https://jsfiddle.net/jun68ykt/t85cdwsu/
|
18
|
+
- [https://jsfiddle.net/jun68ykt/t85cdwsu/5/](https://jsfiddle.net/jun68ykt/t85cdwsu/5/)
|
19
19
|
|
20
20
|
|
21
21
|
参考になれば幸いです。
|