質問編集履歴

3

JsonのDecodeの部分のコードを追記しました。

2018/08/24 05:16

投稿

panyayan
panyayan

スコア36

test CHANGED
File without changes
test CHANGED
@@ -63,3 +63,91 @@
63
63
 
64
64
 
65
65
  ```
66
+
67
+
68
+
69
+ ```JsonDecode
70
+
71
+
72
+
73
+ let url = URL(string: "http://localhost:8000/store/api?store_id=" + store_id)
74
+
75
+ let request = URLRequest(url: url!)
76
+
77
+ let session = URLSession.shared
78
+
79
+
80
+
81
+ let encoder: JSONEncoder = JSONEncoder()
82
+
83
+ encoder.dateEncodingStrategy = .iso8601
84
+
85
+ encoder.outputFormatting = .prettyPrinted
86
+
87
+
88
+
89
+ session.dataTask(with: request){(data, response, error)in if error == nil,
90
+
91
+ let data = data,
92
+
93
+ let response = response as? HTTPURLResponse{
94
+
95
+
96
+
97
+ let decoder: JSONDecoder = JSONDecoder()
98
+
99
+ decoder.dateDecodingStrategy = .iso8601
100
+
101
+ do {
102
+
103
+
104
+
105
+ let json = try decoder.decode(Store.self, from: data)
106
+
107
+
108
+
109
+ // for store in (json.stores){
110
+
111
+ // for photo in (store.photos){
112
+
113
+ // print(photo.path as Any)
114
+
115
+ // }
116
+
117
+ // }
118
+
119
+
120
+
121
+
122
+
123
+ self.store = [json]
124
+
125
+
126
+
127
+ DispatchQueue.main.async {
128
+
129
+ self.nameLabel.text = json.name
130
+
131
+ self.locationLabel.text = json.location
132
+
133
+ }
134
+
135
+
136
+
137
+ } catch {
138
+
139
+ print("error:", error.localizedDescription)
140
+
141
+
142
+
143
+ }
144
+
145
+
146
+
147
+ }
148
+
149
+
150
+
151
+ }.resume()
152
+
153
+ ```

2

まだ残っていたpathの部分をnameに変えました

2018/08/24 05:16

投稿

panyayan
panyayan

スコア36

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
 
11
- 下記のように書いてみましたが`tag[0].path`だと一つしか取得できないので`tag`内の`name`を全て取得できるようにしたいです。
11
+ 下記のように書いてみましたが`tag[0].name`だと一つしか取得できないので`tag`内の`name`を全て取得できるようにしたいです。
12
12
 
13
13
  ```GetJsonDataCode
14
14
 

1

pathの部分をnameに変更しました

2018/08/24 01:37

投稿

panyayan
panyayan

スコア36

test CHANGED
File without changes
test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  ```GetJsonDataCode
14
14
 
15
- store![indexPath.row].tag[0].path
15
+ store![indexPath.row].tag[0].name
16
16
 
17
17
  ```
18
18