ios - Alamofire json 请求 Swift 3

标签 ios iphone swift

<分区>

所以我有以下JSON结构

{"id":"941","title":"dsadadadadsad","description":"dsadadadsadad","added":"2017-01-10 19:00:47"}

现在我正在尝试发出请求并输出数据,但我无法访问 json 属性:object.description

我正在尝试这个,但不起作用

    Alamofire.request("http://localhost:8080/foo.php").responseJSON{ response in
        if let JSON = response.result.value {
            print(JSON["description"])
        }
    }

它不会构建。如何输出"description"的值?

//LE错误 enter image description here

最佳答案

你应该像这样解包值:

if let JSON = response.result.value as? [String: Any] {
            //deal with JSON["description"
}

如果您的 JSON 仅包含字符串值,您也可以像 [String:String] 一样解包

关于ios - Alamofire json 请求 Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41676873/

相关文章:

iphone - 找不到协议(protocol)声明 MKAnnotation

iphone - TabBar 图像插入不传输到 AdHoc 构建

xcode - 通过解析将推送通知发送到您的 iPhone 作为测试

ios - 如何在所有 View 中拥有一个 UIViewController 但不与所有 View 相关

ios - 如何在 didDetermineState 方法中打开应用程序

ios - 如何将闭包作为 Action 传递给添加到 UIView 的点击手势?

ios - 我如何在 Swift 中呈现另一个内部的 View Controller ?

ios - 使用谓词在 TableView 中为单个实体分组 NSFetchedResults

iphone - Autolayout 的尾随空格问题

ios - 如何获取数组中项目的索引?