1
Screenshot Herealamofire object mapper ..爲什麼打印我的項目名稱?
注:這是我的第一個快捷文件
override func viewDidLoad() {
super.viewDidLoad()
let encodingURL = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
Alamofire.request(encodingURL!).responseObject { (response: DataResponse<channel>) in
let MovieResponse = response.result.value
print("결과: \(MovieResponse?.channel?.result as AnyObject)")
print("타이틀: \(MovieResponse?.channel?.title as AnyObject)")
print("토탈카운트: \(MovieResponse?.channel?.totalCount as AnyObject)")
print("전체:\(MovieResponse?.channel as AnyObject)")
print("아이템: \(MovieResponse?.channel?.item as AnyObject)")
print("배우:\(MovieResponse?.channel?.item.first?.actor as AnyObject)")
}
}
注:第二SWIFT文件
import Foundation
import ObjectMapper
class channel : Mappable {
var channel : channelComponents?
required init?(map: Map){ }
func mapping(map: Map) {
self.channel <- map["channel"]
}
}
class channelComponents : Mappable {
var totalCount : Int?
var result : Int?
var title : String?
var item : [item]
required init?(map: Map){
item = []
}
func mapping(map: Map) {
self.totalCount <- map["totalCount"]
self.result <- map["result"]
self.title <- map["q"]
self.item <- map["item"]
}
}
class item : Mappable {
var actor : [Actor]
required init?(map: Map) {
actor = []
}
func mapping(map: Map) {
self.actor <- map["actor"]
}
}
class Actor : Mappable {
var content : String?
var link : String?
required init?(map: Map) { }
func mapping(map: Map) {
self.content <- map["content"]
self.link <- (map["link"])
}
}
輸入
print("아이템: \(MovieResponse?.channel?.item as AnyObject)")
print("배우:\(MovieResponse?.channel?.item.first?.actor as AnyObject)")
輸出
아이템: (
"Movie_D.item"
)
배우:(
"Movie_D.Actor",
"Movie_D.Actor",
"Movie_D.Actor",
"Movie_D.Actor",
"Movie_D.Actor",
"Movie_D.Actor",
"Movie_D.Actor"
)
Movie_D是我的項目名稱。
我想知道演員的名字,但只有我的項目名稱。 (計數是正確的)
你能張貼你的迴應原始價值嗎?另外 - 嘗試翻譯來自hangul的評論,因爲在一個地方,你指的是「演員」,但在代碼中是用韓文寫的。 –
修正了間距和一些語義,使問題在英語中更易於理解。試圖儘可能緊貼作者的語氣/語言,同時凝結和澄清一些我理解的東西(可能不正確,但我不希望)。 – BHendricks
除了我的編輯外,在攻擊答案方面:如果您添加了數據格式@이재진,這將有助於回答問題 - 因爲它似乎有一個「Actor」對象,您想從中獲取'演員的名字',但從顯示的信息我不知道如何存儲在您的應用程序。 – BHendricks