質問編集履歴

1

エラー内容が変わりましたので修正しました

2018/10/18 12:35

投稿

nooon0800
nooon0800

スコア10

test CHANGED
@@ -1 +1 @@
1
- [Go] unexpected end of JSON input が発生する
1
+ [Go] json: cannot unmarshal object into Go value of type が発生する
test CHANGED
@@ -18,7 +18,9 @@
18
18
 
19
19
  その中の処理の一部で、JSONデータをデコードする処理を書こうとしたところ、
20
20
 
21
+ 1行目のデータは処理できますが、2行目のデータで、
22
+
21
- **unexpected end of JSON input **というエラーが発生します。
23
+ ** json: cannot unmarshal object into Go value of type **というエラーが発生します。
22
24
 
23
25
 
24
26
 
@@ -26,7 +28,7 @@
26
28
 
27
29
  実行結果:
28
30
 
29
- 2018/10/18 19:28:37 unexpected end of JSON input
31
+ 2018/10/18 21:25:58 json: cannot unmarshal object into Go value of type []main.Wiki
30
32
 
31
33
  exit status 1
32
34
 
@@ -88,9 +90,13 @@
88
90
 
89
91
  for i := range lines {
90
92
 
91
- if err := json.Unmarshal([]byte(lines[i]), &wikis); err != nil {
93
+ if lines[i] != "" {
92
94
 
95
+ if err := json.Unmarshal([]byte(lines[i]), &wikis); err != nil {
96
+
93
- log.Fatal(err)
97
+ log.Fatal(err)
98
+
99
+ }
94
100
 
95
101
  }
96
102
 
@@ -100,9 +106,11 @@
100
106
 
101
107
  for _, p := range wikis {
102
108
 
103
- fmt.Print(p.Text,"\n")
109
+ if p.Title == "イギリス" {
104
110
 
105
- fmt.Print(p.Title,"\n")
111
+ fmt.Print(p.Text,"\n")
112
+
113
+ }
106
114
 
107
115
  }
108
116