回答編集履歴
2
修正
test
CHANGED
@@ -118,19 +118,19 @@
|
|
118
118
|
|
119
119
|
node = mapper.readTree(new File("XXXXXXXXXX\test.json"));
|
120
120
|
|
121
|
+
|
122
|
+
|
123
|
+
System.out.println(node);
|
124
|
+
|
125
|
+
System.out.println(node.get("status"));
|
126
|
+
|
127
|
+
System.out.println(node.get("data").get("item").get(0).get("userName").asText());
|
128
|
+
|
121
129
|
} catch (IOException e) {
|
122
130
|
|
123
131
|
e.printStackTrace();
|
124
132
|
|
125
133
|
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
System.out.println(node);
|
130
|
-
|
131
|
-
System.out.println(node.get("status"));
|
132
|
-
|
133
|
-
System.out.println(node.get("data").get("item").get(0).get("userName").asText());
|
134
134
|
|
135
135
|
|
136
136
|
|
1
追記
test
CHANGED
@@ -73,3 +73,81 @@
|
|
73
73
|
}
|
74
74
|
|
75
75
|
```
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
# コード
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
どのように取得されているか分かりませんので、適当にローカルにjsonファイルを設置して同じ内容を投入、
|
84
|
+
|
85
|
+
そのファイルからJsonNodeで読み込むように作ってみました。
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
参考まで。
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```java
|
94
|
+
|
95
|
+
import java.io.File;
|
96
|
+
|
97
|
+
import java.io.IOException;
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
import com.fasterxml.jackson.databind.JsonNode;
|
102
|
+
|
103
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
public class JsonReader{
|
108
|
+
|
109
|
+
static ObjectMapper mapper = new ObjectMapper();
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
public static void main(String[] args) {
|
114
|
+
|
115
|
+
JsonNode node = null;
|
116
|
+
|
117
|
+
try {
|
118
|
+
|
119
|
+
node = mapper.readTree(new File("XXXXXXXXXX\test.json"));
|
120
|
+
|
121
|
+
} catch (IOException e) {
|
122
|
+
|
123
|
+
e.printStackTrace();
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
System.out.println(node);
|
130
|
+
|
131
|
+
System.out.println(node.get("status"));
|
132
|
+
|
133
|
+
System.out.println(node.get("data").get("item").get(0).get("userName").asText());
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
出力結果:
|
144
|
+
|
145
|
+
```
|
146
|
+
|
147
|
+
{"status":0,"data":{"item":[{"userName":"xxx","userId":"xxx","icon_image_url":"xxx","description":"xxx"}]}}
|
148
|
+
|
149
|
+
0
|
150
|
+
|
151
|
+
xxx
|
152
|
+
|
153
|
+
```
|