改变语法

时间:2016-11-10 11:34:21

标签: arrays json vapor

我过去常常返回我的MapPoints' (来自数据库)使用以下

extension Sequence where Iterator.Element == MapPoints {
    func makeJSON() -> JSON {
        return .array(self.map { $0.makeJSON() })
    }

    func makeResponse(request: Request) throws -> Response {
        return try makeJSON().makeResponse()
    }
}

现在出现错误"实例成员'数组'不能用于类型' JSON'"

有谁能告诉我应该怎么做?

1 个答案:

答案 0 :(得分:1)

通过初始化JSON(array: [T])

extension Sequence where Iterator.Element == Post {
  func makeJSON() throws -> JSON {
    return try JSON(map { try $0.makeJSON() })
  }

  func makeResponse(request: Request) throws -> Response {
    return try makeJSON().makeResponse()
  }
}