好吧,我有这个服务器响应:如何从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