我想解析数组中的数据,但是我不能。如果您有任何建议,请告诉我。这里是我的数据样本:使用Swift从NSData解析JSON
[{"ListSequence":1,"StarTime":"15.06.2016 09:00","WorkTime":15,"EndTime":"15.06.2016 09:15","Appointment":"","CustomerId":"12345","Name":"","Address":"bla bla"}, {"ListSequence":2,"StarTime":"15.06.2016 09:20","WorkTime":15,"EndTime":"15.06.2016 09:35","Appointment":"","CustomerId":"54321","Name":"","Address":"bla bla"}]
这是我的函数:
func parserJSON(data: NSData){
var names = [String]()
do {
if let ipString = NSString(data:data, encoding: NSUTF8StringEncoding) {
let jsonDictionary = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary
if let sequences = jsonDictionary["ListSequence"] as? [[String: AnyObject]] {
for sequence in sequences {
if let name = jsonDictionary["Name"] as? String{
names.append(name)
}
}
}
}
} catch {
///alert
}
}
您的ListSequence是String并且您的响应是数组 –
JSON是顶级数组,而不是字典。 – Larme
https://github.com/SwiftyJSON/SwiftyJSON试试这个 –