SwiftyJSONでJSON値をループしてUIAlertControllerに表示しようとしています。SwiftyJSONでJSONをループする
if let errorVal = errorVal {
var errorMessages = ""
for (_,subJson):(String, JSON) in errorVal {
errorMessages = errorMessages + String(subJson) + "\n"
}
}
errorVal戻っている:Alamofireを使用して、私のAPIコールで
私はその後、私のVCで、私はとのデータがあることを使用if((responseData.result.value) != nil) {
let json = JSON(responseData.result.value!)
let token = json["api_token"].string
response(token: token, errorVal: json)
} else {
return
}
を使用して、いくつかのJSONデータを返すのです
{
"email" : [
"The email field is required."
],
"password" : [
"The password field is required."
]
}
およびerrorMessages
[
"The email field is required."
]
[
"The password field is required."
]
しかし、私はerrorMessagesではなく、これを表示したい:
The email field is required
The password field is required
どのようにループJSON経由のみが値を得ることができますか?
var newMessage = String(subJson).stringByReplacingOccurrencesOfString("[", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
newMessage = newMessage.stringByReplacingOccurrencesOfString("]", withString: "", options: NSStringCompareOptions.LiteralSearch, range: nil)
errorMessages = errorMessages + newMessage + "\n"