如何从服务器的响应中获取id,content,name的值.来自服务器的响应是AnyObject,如果我打印,它看起来如下所示......
{
content = xxxx
id = 22
name = yyyy
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
Fra*_*kie 18
AnyObject 可以贬低到其他类型的课程,这么多的可能性!
//if you're confident that responseObject will definitely be of this dictionary type
let name = (responseObject as! [String : AnyObject])["name"]
//optional dictionary type
let name = (responseObject as? [String : AnyObject])?["name"]
//or unwrapping, name will be inferred as AnyObject
if let myDictionary = responseObject as? [String : AnyObject] {
let name = myDictionary["name"]
}
//or unwrapping, name will be inferred as String
if let myDictionary = responseObject as? [String : String] {
let name = myDictionary["name"]
}
Run Code Online (Sandbox Code Playgroud)
查看参考.甚至还有一节AnyObject
| 归档时间: |
|
| 查看次数: |
5353 次 |
| 最近记录: |