回答編集履歴
2
追記
test
CHANGED
@@ -161,3 +161,107 @@
|
|
161
161
|
}
|
162
162
|
|
163
163
|
```
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
----
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
データのフォーマットが決まっているのであれば、Itemクラスのようなものを定義すると、List/Mapのまま扱うよりも楽ちんかも。
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
```java
|
176
|
+
|
177
|
+
import com.fasterxml.jackson.annotation.JsonProperty;
|
178
|
+
|
179
|
+
import com.fasterxml.jackson.core.type.TypeReference;
|
180
|
+
|
181
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
182
|
+
|
183
|
+
import java.util.List;
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
public class HogeJson2 {
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
public static void main(final String[] args) throws Exception {
|
192
|
+
|
193
|
+
final ObjectMapper objectMapper = new ObjectMapper();
|
194
|
+
|
195
|
+
final List<Item> result3 = objectMapper.readValue(jsonString3, new TypeReference<List<Item>>() {
|
196
|
+
|
197
|
+
});
|
198
|
+
|
199
|
+
System.out.println("---- result3 --------");
|
200
|
+
|
201
|
+
System.out.println(result3);
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
// ---- result3 --------
|
206
|
+
|
207
|
+
// [item: <@id:(URL), name:(TOP)>, item: <@id:(URL), name:(第二階層)>, item: <@id:(URL), name:(第三階層)>]
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
public static class Item {
|
214
|
+
|
215
|
+
@JsonProperty("@id")
|
216
|
+
|
217
|
+
public String id;
|
218
|
+
|
219
|
+
public String name;
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
@Override
|
224
|
+
|
225
|
+
public String toString() {
|
226
|
+
|
227
|
+
return String.format("item: <@id:(%s), name:(%s)>", id, name);
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
static final String jsonString3 = " [\n" +
|
236
|
+
|
237
|
+
" {\n" +
|
238
|
+
|
239
|
+
" \"@id\": \"URL\",\n" +
|
240
|
+
|
241
|
+
" \"name\": \"TOP\"\n" +
|
242
|
+
|
243
|
+
" },\n" +
|
244
|
+
|
245
|
+
" {\n" +
|
246
|
+
|
247
|
+
" \"@id\": \"URL\",\n" +
|
248
|
+
|
249
|
+
" \"name\":\"第二階層\"\n" +
|
250
|
+
|
251
|
+
" },\n" +
|
252
|
+
|
253
|
+
" {\n" +
|
254
|
+
|
255
|
+
" \"@id\": \"URL\",\n" +
|
256
|
+
|
257
|
+
" \"name\": \"第三階層\"\n" +
|
258
|
+
|
259
|
+
" }\n" +
|
260
|
+
|
261
|
+
" ]";
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
```
|
1
typo
test
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
|
6
6
|
|
7
|
-
MapやListにしてしまえば、あとはいかようにも
|
7
|
+
MapやListにしてしまえば、あとはいかようにも。
|
8
8
|
|
9
9
|
|
10
10
|
|