質問編集履歴

3

コード書き換え

2017/03/20 07:36

投稿

vike
vike

スコア17

test CHANGED
File without changes
test CHANGED
@@ -14,13 +14,11 @@
14
14
 
15
15
 
16
16
 
17
-
17
+ ObjectMapper mapper = new ObjectMapper();
18
18
 
19
19
  try {
20
20
 
21
- //jacksonのマッパーを設定
21
+
22
-
23
- ObjectMapper mapper = new ObjectMapper();
24
22
 
25
23
  JackSon response = mapper.readValue(
26
24
 

2

コード変更

2017/03/20 07:36

投稿

vike
vike

スコア17

test CHANGED
File without changes
test CHANGED
@@ -16,21 +16,41 @@
16
16
 
17
17
 
18
18
 
19
+ try {
20
+
21
+ //jacksonのマッパーを設定
22
+
19
23
  ObjectMapper mapper = new ObjectMapper();
20
-
21
- try {
22
24
 
23
25
  JackSon response = mapper.readValue(
24
26
 
25
27
 
26
28
 
27
-
29
+ new URL("http://express.heartrails.com/api/json?method=getAreas"),
28
30
 
29
- new URL("http://express.heartrails.com/api/json?method=getAreas"),
31
+ JackSon.class);
30
32
 
33
+
34
+
35
+ String m = response.get("response").get(0).get("area").asText();
36
+
37
+
38
+
31
- JackSon.class);
39
+ super.onCreate(savedInstanceState);
40
+
41
+
42
+
43
+ setContentView(R.layout.activity_main);
32
44
 
33
45
 
46
+
47
+ TextView textView = (TextView) findViewById(R.id.text_view);
48
+
49
+
50
+
51
+ textView.setText(String.valueOf(m));
52
+
53
+
34
54
 
35
55
  } catch (IOException e) {
36
56
 
@@ -42,33 +62,15 @@
42
62
 
43
63
 
44
64
 
45
- super.onCreate(savedInstanceState);
46
-
47
-
48
-
49
- setContentView(R.layout.activity_main);
50
-
51
-
52
-
53
- TextView textView = (TextView) findViewById(R.id.text_view);
54
-
55
-
56
-
57
- textView.setText();
58
-
59
-
60
-
61
- }
62
-
63
-
64
-
65
-
66
-
67
65
  }
68
66
 
69
67
 
70
68
 
71
69
  ```
70
+
71
+
72
+
73
+ 上記のコードでは、response.getのgetに Cannot resolve method 'get(java.lang.String)'と言うエラーが出ています。
72
74
 
73
75
 
74
76
 

1

文法の修正

2017/03/20 06:30

投稿

vike
vike

スコア17

test CHANGED
File without changes
test CHANGED
@@ -8,45 +8,43 @@
8
8
 
9
9
  public class MainActivity extends AppCompatActivity {
10
10
 
11
+ @Override
11
12
 
12
-
13
- public static void main( String[] args ) throws IOException
13
+ protected void onCreate(Bundle savedInstanceState){
14
-
15
- {
16
14
 
17
15
 
18
16
 
17
+
19
18
 
19
+ ObjectMapper mapper = new ObjectMapper();
20
20
 
21
- ObjectMapper mapper = new ObjectMapper();
21
+ try {
22
22
 
23
- JackSon response = mapper.readValue(
23
+ JackSon response = mapper.readValue(
24
24
 
25
25
 
26
26
 
27
-
27
+
28
28
 
29
- new URL("http://express.heartrails.com/api/json?method=getAreas"),
29
+ new URL("http://express.heartrails.com/api/json?method=getAreas"),
30
30
 
31
- JackSon.class);
31
+ JackSon.class);
32
32
 
33
+
33
34
 
35
+ } catch (IOException e) {
34
36
 
37
+ e.printStackTrace();
38
+
35
- }
39
+ }
36
40
 
37
41
 
38
42
 
39
43
 
40
44
 
41
- @Override
42
-
43
- protected void onCreate(Bundle savedInstanceState) {
44
-
45
45
  super.onCreate(savedInstanceState);
46
46
 
47
-
48
-
49
-
47
+
50
48
 
51
49
  setContentView(R.layout.activity_main);
52
50
 
@@ -62,7 +60,13 @@
62
60
 
63
61
  }
64
62
 
63
+
64
+
65
+
66
+
65
67
  }
68
+
69
+
66
70
 
67
71
  ```
68
72