回答編集履歴
1
追記しました
test
CHANGED
@@ -7,3 +7,61 @@
|
|
7
7
|
|
8
8
|
|
9
9
|
なのではないですか?
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
#追記
|
14
|
+
|
15
|
+
```Swift
|
16
|
+
|
17
|
+
json.forEach { (_, json) in
|
18
|
+
|
19
|
+
let nutrition: [String: String?] = [
|
20
|
+
|
21
|
+
"barcode": json["barcode"].string
|
22
|
+
|
23
|
+
]
|
24
|
+
|
25
|
+
self.nutritions.append(nutrition)
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
self.foodGet(json["barcode"] as! String)
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
よくよくみるとループして`nutrition`を`nutritions`に突っ込んでいるみたいなので
|
36
|
+
|
37
|
+
`json["barcode"].string!`したところで`nil`になりますよねそりゃ。。。
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
JSONの情報のなかで`barcode`単体なら,
|
42
|
+
|
43
|
+
ループは外してあげれば良いし、今回はそうではなさそうなので
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```Swift
|
48
|
+
|
49
|
+
json.forEach { (_, json) in
|
50
|
+
|
51
|
+
let nutrition: [String: String?] = [
|
52
|
+
|
53
|
+
"barcode": json["barcode"].string
|
54
|
+
|
55
|
+
]
|
56
|
+
|
57
|
+
self.foodGet(json["barcode"].string!)
|
58
|
+
|
59
|
+
self.nutritions.append(nutrition)
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
こうやればJSON内のすべての`barcode`情報を渡せませんかね?
|
66
|
+
|
67
|
+
|