Quando la decodifica risposta JSON dal webservice ottengo un errore che dice:Impossibile lanciare valore di tipo '__NSArrayM' (0x34df0900) per 'NSDictionary' SWIFT
Could not cast value of type '__NSArrayM' (0x34df0900) to 'NSDictionary'
ho provato tante soluzioni trovate anche in StackOverflow, ma niente funziona.
My Code:
let jsonData:NSDictionary = (NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers , error: &error) as? NSDictionary)!
let success:NSInteger = jsonData.valueForKey("success") as! NSInteger
risposta dal servizio Web:
[
{
"id": "1",
"title": "bmw",
"price": "500.00",
"description": "330",
"addedDate": "2015-05-18 00:00:00",
"user_id": "1",
"user_name": "CANOVAS",
"user_zipCode": "32767",
"category_id": "1",
"category_label": "VEHICULES",
"subcategory_id": "2",
"subcategory_label": "Motos",
"bdd": {}
}
]
Grazie per il vostro aiuto
io sono, non davanti al mio mac fino a stasera, ti dirò che stasera! Grazie per il vostro messaggio ! – f1rstsurf
ora ho: "Operatore binario! = 'Non può essere applicato agli operandi di tipo' NSArray? ' "and 'nil' per" se jsonData ["message"] as? NSArray! = nil {" – f1rstsurf
come usare qualcosa come' NSArray.count> 0' come cosa per verificare se non è vuoto o vuoto? –