回答編集履歴
2
修正
answer
CHANGED
@@ -58,14 +58,14 @@
|
|
58
58
|
JsonNode node = null;
|
59
59
|
try {
|
60
60
|
node = mapper.readTree(new File("XXXXXXXXXX\test.json"));
|
61
|
+
|
62
|
+
System.out.println(node);
|
63
|
+
System.out.println(node.get("status"));
|
64
|
+
System.out.println(node.get("data").get("item").get(0).get("userName").asText());
|
61
65
|
} catch (IOException e) {
|
62
66
|
e.printStackTrace();
|
63
67
|
}
|
64
68
|
|
65
|
-
System.out.println(node);
|
66
|
-
System.out.println(node.get("status"));
|
67
|
-
System.out.println(node.get("data").get("item").get(0).get("userName").asText());
|
68
|
-
|
69
69
|
}
|
70
70
|
}
|
71
71
|
```
|
1
追記
answer
CHANGED
@@ -35,4 +35,43 @@
|
|
35
35
|
}
|
36
36
|
}
|
37
37
|
}
|
38
|
+
```
|
39
|
+
|
40
|
+
# コード
|
41
|
+
|
42
|
+
どのように取得されているか分かりませんので、適当にローカルにjsonファイルを設置して同じ内容を投入、
|
43
|
+
そのファイルからJsonNodeで読み込むように作ってみました。
|
44
|
+
|
45
|
+
参考まで。
|
46
|
+
|
47
|
+
```java
|
48
|
+
import java.io.File;
|
49
|
+
import java.io.IOException;
|
50
|
+
|
51
|
+
import com.fasterxml.jackson.databind.JsonNode;
|
52
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
53
|
+
|
54
|
+
public class JsonReader{
|
55
|
+
static ObjectMapper mapper = new ObjectMapper();
|
56
|
+
|
57
|
+
public static void main(String[] args) {
|
58
|
+
JsonNode node = null;
|
59
|
+
try {
|
60
|
+
node = mapper.readTree(new File("XXXXXXXXXX\test.json"));
|
61
|
+
} catch (IOException e) {
|
62
|
+
e.printStackTrace();
|
63
|
+
}
|
64
|
+
|
65
|
+
System.out.println(node);
|
66
|
+
System.out.println(node.get("status"));
|
67
|
+
System.out.println(node.get("data").get("item").get(0).get("userName").asText());
|
68
|
+
|
69
|
+
}
|
70
|
+
}
|
71
|
+
```
|
72
|
+
出力結果:
|
73
|
+
```
|
74
|
+
{"status":0,"data":{"item":[{"userName":"xxx","userId":"xxx","icon_image_url":"xxx","description":"xxx"}]}}
|
75
|
+
0
|
76
|
+
xxx
|
38
77
|
```
|