質問編集履歴
4
gせいjrpppp;
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,285 +1 @@
|
|
1
|
-
### 前提・実現したいこと
|
2
|
-
|
3
|
-
nodes = [ {type: "h1",value: 1,children: [{type: "p",
|
4
|
-
|
5
|
-
value: 2,
|
6
|
-
|
7
|
-
}
|
8
|
-
|
9
|
-
],
|
10
|
-
|
11
|
-
},
|
12
|
-
|
13
|
-
{
|
14
|
-
|
15
|
-
value: 3,
|
16
|
-
|
17
|
-
type: "h2",
|
18
|
-
|
19
|
-
children: [
|
20
|
-
|
21
|
-
{
|
22
|
-
|
23
|
-
children: [
|
24
|
-
|
25
|
-
{
|
26
|
-
|
27
|
-
type: "p",
|
28
|
-
|
29
|
-
value: 5,
|
30
|
-
|
31
|
-
},
|
32
|
-
|
33
|
-
{
|
34
|
-
|
35
|
-
type: "h3",
|
36
|
-
|
37
|
-
value: 6,
|
38
|
-
|
39
|
-
},
|
40
|
-
|
41
|
-
],
|
42
|
-
|
43
|
-
type: "p",
|
44
|
-
|
45
|
-
value: 4,
|
46
|
-
|
47
|
-
},
|
48
|
-
|
49
|
-
{
|
50
|
-
|
51
|
-
type: "p",
|
52
|
-
|
53
|
-
value: 7,
|
54
|
-
|
55
|
-
},
|
56
|
-
|
57
|
-
{
|
58
|
-
|
59
|
-
type: "h3",
|
60
|
-
|
61
|
-
value: 8,
|
62
|
-
|
63
|
-
children: [
|
64
|
-
|
65
|
-
{
|
66
|
-
|
67
|
-
type: "h3",
|
68
|
-
|
69
|
-
value: 9,
|
70
|
-
|
71
|
-
},
|
72
|
-
|
73
|
-
],
|
74
|
-
|
75
|
-
},
|
76
|
-
|
77
|
-
],
|
78
|
-
|
79
|
-
},
|
80
|
-
|
81
|
-
{
|
82
|
-
|
83
|
-
type: "h2",
|
84
|
-
|
85
|
-
value: 11,
|
86
|
-
|
87
|
-
children: [
|
88
|
-
|
89
|
-
{
|
90
|
-
|
91
|
-
type: "p",
|
92
|
-
|
93
|
-
value: 10,
|
94
|
-
|
95
|
-
},
|
96
|
-
|
97
|
-
],
|
98
|
-
|
99
|
-
},
|
100
|
-
|
101
|
-
]
|
102
|
-
|
103
|
-
とするときnodeの要素を取り出したい。
|
104
|
-
|
105
|
-
|
1
|
+
sdgzxb;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
### 発生している問題・エラーメッセージ
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
```
|
116
|
-
|
117
|
-
```python
|
118
|
-
|
119
|
-
import json
|
120
|
-
|
121
|
-
nodes = [
|
122
|
-
|
123
|
-
{
|
124
|
-
|
125
|
-
'type': "h1",
|
126
|
-
|
127
|
-
'value': 1,
|
128
|
-
|
129
|
-
'children': [
|
130
|
-
|
131
|
-
{
|
132
|
-
|
133
|
-
'type': "p",
|
134
|
-
|
135
|
-
'value': 2,
|
136
|
-
|
137
|
-
}
|
138
|
-
|
139
|
-
],
|
140
|
-
|
141
|
-
},
|
142
|
-
|
143
|
-
{
|
144
|
-
|
145
|
-
'value': 3,
|
146
|
-
|
147
|
-
'type': "h2",
|
148
|
-
|
149
|
-
'children': [
|
150
|
-
|
151
|
-
{
|
152
|
-
|
153
|
-
'children': [
|
154
|
-
|
155
|
-
{
|
156
|
-
|
157
|
-
'type': "p",
|
158
|
-
|
159
|
-
'value': 5,
|
160
|
-
|
161
|
-
},
|
162
|
-
|
163
|
-
{
|
164
|
-
|
165
|
-
'type': "h3",
|
166
|
-
|
167
|
-
'value': 6,
|
168
|
-
|
169
|
-
},
|
170
|
-
|
171
|
-
],
|
172
|
-
|
173
|
-
'type': "p",
|
174
|
-
|
175
|
-
'value': 4,
|
176
|
-
|
177
|
-
},
|
178
|
-
|
179
|
-
{
|
180
|
-
|
181
|
-
'type': "p",
|
182
|
-
|
183
|
-
'value': 7,
|
184
|
-
|
185
|
-
},
|
186
|
-
|
187
|
-
{
|
188
|
-
|
189
|
-
'type': "h3",
|
190
|
-
|
191
|
-
'value': 8,
|
192
|
-
|
193
|
-
'children': [
|
194
|
-
|
195
|
-
{
|
196
|
-
|
197
|
-
'type': "h3",
|
198
|
-
|
199
|
-
'value': 9,
|
200
|
-
|
201
|
-
},
|
202
|
-
|
203
|
-
],
|
204
|
-
|
205
|
-
},
|
206
|
-
|
207
|
-
],
|
208
|
-
|
209
|
-
},
|
210
|
-
|
211
|
-
{
|
212
|
-
|
213
|
-
'type': "h2",
|
214
|
-
|
215
|
-
'value': 11,
|
216
|
-
|
217
|
-
'children': [
|
218
|
-
|
219
|
-
{
|
220
|
-
|
221
|
-
'type': "p",
|
222
|
-
|
223
|
-
'value': 10,
|
224
|
-
|
225
|
-
},
|
226
|
-
|
227
|
-
],
|
228
|
-
|
229
|
-
},
|
230
|
-
|
231
|
-
]
|
232
|
-
|
233
|
-
d =json.loads(nodes)
|
234
|
-
|
235
|
-
print.pprint(d)
|
236
|
-
|
237
|
-
```
|
238
|
-
|
239
|
-
TypeError Traceback (most recent call last)
|
240
|
-
|
241
|
-
<ipython-input-36-0814ecaab146> in <module>
|
242
|
-
|
243
|
-
56 },
|
244
|
-
|
245
|
-
57 ]
|
246
|
-
|
247
|
-
---> 58 d =json.loads(nodes)
|
248
|
-
|
249
|
-
59 print.pprint(d)
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
~\anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
|
254
|
-
|
255
|
-
339 else:
|
256
|
-
|
257
|
-
340 if not isinstance(s, (bytes, bytearray)):
|
258
|
-
|
259
|
-
--> 341 raise TypeError(f'the JSON object must be str, bytes or bytearray, '
|
260
|
-
|
261
|
-
342 f'not {s.__class__.__name__}')
|
262
|
-
|
263
|
-
343 s = s.decode(detect_encoding(s), 'surrogatepass')
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
TypeError: the JSON object must be str, bytes or bytearray, not list
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
```
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
### 補足情報(FW/ツールのバージョンなど)
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
python3.7
|
3
初心者 jsonを使っていましたがだめでした
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
python辞書、配列の要素の取り出し方について
|
1
|
+
python辞書、配列の要素のjsonでの取り出し方について
|
test
CHANGED
@@ -114,18 +114,162 @@
|
|
114
114
|
|
115
115
|
```
|
116
116
|
|
117
|
+
```python
|
118
|
+
|
119
|
+
import json
|
120
|
+
|
121
|
+
nodes = [
|
122
|
+
|
123
|
+
{
|
124
|
+
|
125
|
+
'type': "h1",
|
126
|
+
|
127
|
+
'value': 1,
|
128
|
+
|
129
|
+
'children': [
|
130
|
+
|
131
|
+
{
|
132
|
+
|
117
|
-
p
|
133
|
+
'type': "p",
|
134
|
+
|
118
|
-
|
135
|
+
'value': 2,
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
],
|
140
|
+
|
141
|
+
},
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
'value': 3,
|
146
|
+
|
119
|
-
|
147
|
+
'type': "h2",
|
148
|
+
|
120
|
-
|
149
|
+
'children': [
|
150
|
+
|
151
|
+
{
|
152
|
+
|
153
|
+
'children': [
|
154
|
+
|
155
|
+
{
|
156
|
+
|
121
|
-
|
157
|
+
'type': "p",
|
158
|
+
|
122
|
-
|
159
|
+
'value': 5,
|
160
|
+
|
161
|
+
},
|
162
|
+
|
163
|
+
{
|
164
|
+
|
165
|
+
'type': "h3",
|
166
|
+
|
167
|
+
'value': 6,
|
168
|
+
|
169
|
+
},
|
170
|
+
|
171
|
+
],
|
172
|
+
|
173
|
+
'type': "p",
|
174
|
+
|
175
|
+
'value': 4,
|
176
|
+
|
177
|
+
},
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
'type': "p",
|
182
|
+
|
183
|
+
'value': 7,
|
184
|
+
|
185
|
+
},
|
186
|
+
|
187
|
+
{
|
188
|
+
|
189
|
+
'type': "h3",
|
190
|
+
|
191
|
+
'value': 8,
|
192
|
+
|
193
|
+
'children': [
|
194
|
+
|
195
|
+
{
|
196
|
+
|
197
|
+
'type': "h3",
|
198
|
+
|
199
|
+
'value': 9,
|
200
|
+
|
201
|
+
},
|
202
|
+
|
203
|
+
],
|
204
|
+
|
205
|
+
},
|
206
|
+
|
207
|
+
],
|
208
|
+
|
209
|
+
},
|
210
|
+
|
211
|
+
{
|
212
|
+
|
213
|
+
'type': "h2",
|
214
|
+
|
123
|
-
value: 1,
|
215
|
+
'value': 11,
|
216
|
+
|
124
|
-
|
217
|
+
'children': [
|
218
|
+
|
219
|
+
{
|
220
|
+
|
125
|
-
|
221
|
+
'type': "p",
|
222
|
+
|
223
|
+
'value': 10,
|
224
|
+
|
225
|
+
},
|
226
|
+
|
227
|
+
],
|
228
|
+
|
229
|
+
},
|
230
|
+
|
231
|
+
]
|
232
|
+
|
233
|
+
d =json.loads(nodes)
|
234
|
+
|
235
|
+
print.pprint(d)
|
126
236
|
|
127
237
|
```
|
128
238
|
|
239
|
+
TypeError Traceback (most recent call last)
|
240
|
+
|
241
|
+
<ipython-input-36-0814ecaab146> in <module>
|
242
|
+
|
243
|
+
56 },
|
244
|
+
|
245
|
+
57 ]
|
246
|
+
|
247
|
+
---> 58 d =json.loads(nodes)
|
248
|
+
|
249
|
+
59 print.pprint(d)
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
~\anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
|
254
|
+
|
255
|
+
339 else:
|
256
|
+
|
257
|
+
340 if not isinstance(s, (bytes, bytearray)):
|
258
|
+
|
259
|
+
--> 341 raise TypeError(f'the JSON object must be str, bytes or bytearray, '
|
260
|
+
|
261
|
+
342 f'not {s.__class__.__name__}')
|
262
|
+
|
263
|
+
343 s = s.decode(detect_encoding(s), 'surrogatepass')
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
TypeError: the JSON object must be str, bytes or bytearray, not list
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
```
|
272
|
+
|
129
273
|
|
130
274
|
|
131
275
|
|
2
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
python辞書の要素の取り出し方について
|
1
|
+
python辞書、配列の要素の取り出し方について
|
test
CHANGED
@@ -102,7 +102,7 @@
|
|
102
102
|
|
103
103
|
とするときnodeの要素を取り出したい。
|
104
104
|
|
105
|
-
ex)type
|
105
|
+
ex)typeの"h2"やvalueの"11"
|
106
106
|
|
107
107
|
|
108
108
|
|
1
タイトル変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
辞書の要素の取り出し方について
|
1
|
+
python辞書の要素の取り出し方について
|
test
CHANGED
@@ -1,18 +1,6 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
nodes = [
|
4
|
-
|
5
|
-
{
|
6
|
-
|
7
|
-
|
3
|
+
nodes = [ {type: "h1",value: 1,children: [{type: "p",
|
8
|
-
|
9
|
-
value: 1,
|
10
|
-
|
11
|
-
children: [
|
12
|
-
|
13
|
-
{
|
14
|
-
|
15
|
-
type: "p",
|
16
4
|
|
17
5
|
value: 2,
|
18
6
|
|