前端之家收集整理的这篇文章主要介绍了
swift的json解析,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
let data=[{"userList":[
{"id":"0c870834932347bb","phone":"9999","uname":"9999","utype":"0","upassword":"9999","ipaddress":"3","utime":"2017-06-30 14:50:27"},{"id":"0cdf458d93bc4b10","phone":"54321","uname":"54321","upassword":"54321","ipaddress":"1","utime":"2017-06-29 19:11:42"},{"id":"085fe33134f44f10","phone":"1111","uname":"1111","upassword":"1111","ipaddress":"4","utime":"2017-06-29 15:44:05"},{"id":"1584f6f7f4e24597","phone":"1234","uname":"1234","upassword":"1234","ipaddress":"2","utime":"2017-06-29 13:08:06"}],"resultCode":"999"}]
let jsonArr = try! JSONSerialization.jsonObject(with:data!,options:JSONSerialization.ReadingOptions.mutableContainers) as! [[String: Any]]
for json in jsonArr {
let code1=(json["resultCode"])as! String
if code1=="999"{
print("连接成功")
let code2:NSArray=(json["userList"])as! NSArray
let code3:NSDictionary=(code2[0])as! NSDictionary
(code3["id"])as! String
}
}
原文链接:https://www.f2er.com/swift/321363.html