-1
我們有一個JSON有效載荷:如何將JSON有效載荷轉換爲自定義對象?
{
"aps": {
"alert": {
"title": "Payload",
"body": "Lets map this thing"
},
},
"type": "alert",
"message": "This is a message",
}
自定義對象已經創建:
class PushNotificationDetail {
var title: String //operation
var body: String //message
var type: detailType
var message: String?
init(title: String, body: String, type: detailType, message: string?){
self.title = title
self.body = body
self.type = type
self.message = message
}
}
問題是正確映射它創建的對象,這將是實現這一目標的最佳方式是什麼?
https://www.raywenderlich.com/ 150322/swift-json-tutorial-2或https://developer.apple.com/swift/blog/?id=37 – CodeNinja
我認爲你應該把標題和正文放在名爲'alert'或'detailType'的模型中(I thi nk您正在使用'detailType',順便說一句,您應該用大寫字母來命名類型,例如DetailType) – 3stud1ant3
您實際上在映射時遇到了什麼問題?你的問題顯示沒有試圖做任何映射到解析JSON的任何嘗試。 – rmaddy