回答編集履歴
1
調製
test
CHANGED
@@ -1,3 +1,59 @@
|
|
1
1
|
document.writeはよほどのことがない限りつかってはいけません
|
2
2
|
|
3
3
|
具体的なjsonデータがないので正確な回答がしづらいですね
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```javascript
|
8
|
+
|
9
|
+
<script>
|
10
|
+
|
11
|
+
const getJSON=async()=>{
|
12
|
+
|
13
|
+
const url="my.json";
|
14
|
+
|
15
|
+
const data=await fetch(url).then(res=>res.json());
|
16
|
+
|
17
|
+
const body=document.querySelector('body');
|
18
|
+
|
19
|
+
body.append(Object.assign(document.createElement('h1'),{textContent:"JSON TEST"}));
|
20
|
+
|
21
|
+
const lis=data.map(x=>Object.assign(document.createElement('li'),{textContent:x.name}));
|
22
|
+
|
23
|
+
body.append(
|
24
|
+
|
25
|
+
lis.reduce((x,y)=>(x.append(y),x),Object.assign(document.createElement('ul')))
|
26
|
+
|
27
|
+
);
|
28
|
+
|
29
|
+
};
|
30
|
+
|
31
|
+
window.addEventListener('DOMContentLoaded', ()=>{
|
32
|
+
|
33
|
+
getJSON();
|
34
|
+
|
35
|
+
});
|
36
|
+
|
37
|
+
</script>
|
38
|
+
|
39
|
+
Hello World!<br>
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
- my.json
|
46
|
+
|
47
|
+
```json
|
48
|
+
|
49
|
+
[
|
50
|
+
|
51
|
+
{"name":"aaa"},
|
52
|
+
|
53
|
+
{"name":"bbb"},
|
54
|
+
|
55
|
+
{"name":"ccc"}
|
56
|
+
|
57
|
+
]
|
58
|
+
|
59
|
+
```
|