質問編集履歴
1
swiftファイルを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,13 +6,15 @@
|
|
6
6
|
|
7
7
|
実現したいこととしては、
|
8
8
|
|
9
|
-
"http://52.194.224.50/srv.php"に
|
9
|
+
"http://52.194.224.50/srv.php"に画像URLが含まれているjsonファイルを返すよう要求し、
|
10
|
+
|
10
|
-
|
11
|
+
サーバーから返ってきた
|
12
|
+
|
11
|
-
"http://52.194.224.50/data/coupon.json"のjsonファイル
|
13
|
+
"http://52.194.224.50/data/coupon.json"のjsonファイルに含まれる画像URLを元に、
|
12
|
-
|
14
|
+
|
13
|
-
"http://52.194.224.50/data/image/coupon/noimage.png"の画像
|
15
|
+
"http://52.194.224.50/data/image/coupon/noimage.png"の画像を
|
14
|
-
|
16
|
+
|
15
|
-
アプリ
|
17
|
+
アプリで表示させるという処理です。
|
16
18
|
|
17
19
|
|
18
20
|
|
@@ -20,6 +22,100 @@
|
|
20
22
|
|
21
23
|
|
22
24
|
|
25
|
+
※追記
|
26
|
+
|
27
|
+
なんとかjsonファイルを取得することはできたので、
|
28
|
+
|
29
|
+
その中に含まれるURLを元に、サーバーの画像を取得したいです......
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
```Swift
|
36
|
+
|
37
|
+
import UIKit
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
class ViewController: UIViewController {
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
@IBOutlet weak var image1: UIImageView!
|
46
|
+
|
47
|
+
//サーバーから返ってきたURL情報を元に、画像を表示したい
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
override func viewDidLoad() {
|
52
|
+
|
53
|
+
super.viewDidLoad()
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
let postString = "command=getCoupon"
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
var request = URLRequest(url: URL(string: "http://52.194.224.50/srv.php")!)
|
62
|
+
|
63
|
+
request.httpMethod = "POST"
|
64
|
+
|
65
|
+
request.httpBody = postString.data(using: .utf8)
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
let task = URLSession.shared.dataTask(with: request, completionHandler: {
|
70
|
+
|
71
|
+
(data, response, error) in
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
if error != nil {return }
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
do {
|
80
|
+
|
81
|
+
let json = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.allowFragments)
|
82
|
+
|
83
|
+
let top = json as! NSArray
|
84
|
+
|
85
|
+
for roop in top {
|
86
|
+
|
87
|
+
let next = roop as! NSDictionary
|
88
|
+
|
89
|
+
print(next["imageUrl"] as! String)
|
90
|
+
|
91
|
+
//サーバーから返ってきた"imageUrl"を元に、サーバーから画像を取得したい
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
} catch {
|
96
|
+
|
97
|
+
print(error)
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
})
|
104
|
+
|
105
|
+
task.resume()
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
|
23
119
|
```PHP
|
24
120
|
|
25
121
|
<?php
|