ios - Alamofire.requestObject 自定义案例未调用

标签 ios json swift mapping alamofire

由于很多人都有这个错误,我也有,我不知道为什么“responseObject 无法使用类型为 ((JSONResponse>) -> _) 的参数列表调用”

我还使用 Alamofire+ObjectMapper 进行 JSON 映射

有人知道 Alamofire 出了什么问题吗?它经常出现错误,可能对理解 Alamofire 有什么想法吗?

import Foundation
import Alamofire
import AlamofireObjectMapper
import ObjectMapper

public protocol Mappable {
    static func newInstance(map: Map) -> Mappable?
    mutating func mapping(map: Map)
}

class JMapping {



    func getJSON() {

        let url = "http://www.somestringToJson/json.json"


        Alamofire
        .request(.GET, url, parameters: nil)


            .responseObject { (response: JSONResponse?) in
                println(response?.title)
                if let events = response?.events {
                    for event in events {
                        println(event.id)
                        println(event.title)

                    }
                }
        }
    }

}




class JSONResponse: Mappable {
    var title: String?
    var id: String?
    var events: [EventsResponse]?


    class func newInstance(map: Map) -> Mappable? {
            return JSONResponse()
        }


    func mapping(map: Map) {
        title <- map["title"]
        id <- map["id"]
        events <- map["events"]

    }


}

class EventsResponse: Mappable {
    var title: String?
    var id: String?
    var content: [ContentResponse]?

    class func newInstance(map:Map) -> Mappable? {
        return EventsResponse()
    }

    func mapping(map: Map) {
        title <- map["title"]
        id <- map["id"]
        content <- map["content"]
    }

}

class ContentResponse: Mappable{
    var content_type: String?
    var visible: Bool?
    var data: NSArray?

    class func newInstance(map: Map) -> Mappable? {
        return ContentResponse()
    }

    func mapping(map: Map) {
        content_type <- map["content_type"]
        visible <- map["visible"]
        data <- map["data"]
    }
}

最佳答案

            Alamofire.request(.GET, "http://yoururl.de")
                    .response { (request, response, data, error) in

                    }

基本的 alamofire 获取请求如下所示。请求完成后调用响应。 之后,我建议使用 SwiftyJSON 并转换您的响应数据。

    if let data = (responseBody as NSString).dataUsingEncoding(NSUTF8StringEncoding) {
        let json = JSON(data: data)
        println(json)
    }

关于ios - Alamofire.requestObject 自定义案例未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32096063/

相关文章:

objective-c - 创建全向 ScrollView

ios - 从 UITableViewController 创建时何时释放 UINavigationController?

javascript - 如何使用backbone.js划分JSON集合结果

swift - 尝试打印两个值时出错

ios - 可选类型 'String??' 未展开

ios - 从 SOAP 响应中获取 JSON

ios - 计算动态 UILabel 的行数 (iOS7)

iphone - 当我在不同类别中有多个同名节点时,如何使用 NSXMLParser 读取 XML?

javascript - 如何解析这种类型的文本?

python - 如何将 json 转换为 Python 列表?