好吧,我有這個服務器響應:如何從JSON數組中獲取字符串數組?
{
cars = (
{
"color" = red;
"model" = ferrari;
"othersAtributes" = others atributes;
},{
"color" = blue;
"model" = honda;
"othersAtributes" = others atributes;
},{
"color" = green;
"model" = ford;
"othersAtributes" = others atributes;
},{
"color" = yellow;
"model" = porshe;
"othersAtributes" = others atributes;
}
)
}
我需要汽車模型的列表。一系列車型,設置爲一個列表。
我該如何轉換?喜歡這個? '讓有效載荷=響應爲? [字符串:任何]'? – steibour
我假設服務器有效載荷是標準的JSON格式,並且您使用'NSURLSessionDataTask'來請求它,以便獲得一個'Data'對象。那麼答案將是@Vignesh J發佈的內容。儘管我建議使用'[String:Any]'來更快速地使用Swift-y。 'let payload:[String:Any] = NSJSONSerialization.JSONObjectWithData(data,options:NSJSONReadingOptions.MutableContainers,error:nil)as! [String:Any]' – xiangxin
我用alamofire – steibour