我使用Deployd作为我的Swift应用程序的后端。这就是我目前查询JSON数据的方式。我需要限制从查询返回的对象数量。我自己实现了分页部分。我只想知道如何在查询中嵌入下面提到的$limit
方法。任何建议都将不胜感激。
http://docs.deployd.com/docs/collections/reference/querying-collections.html#s- $限制-1416
来自Deployd的文档:
$limit
命令允许您限制对象的数量 从查询返回。这通常用于分页,以及$skip
。// Return the top 10 scores { $sort: {score: -1}, $limit: 10 }
import Foundation
class ObjectHandler {
var greetings: [initTable] = []
init(filename: String) {
//filter data
let fileP = NSURL(string: "http://localhost:2403/users/me")
let jsonD = NSData(contentsOfURL:fileP!)
let jso = JSON(data: jsonD!, options: NSJSONReadingOptions.AllowFragments, error: nil)
var id = jso["id"]
let filePath = NSURL(string: "http://localhost:2403/postedjob")
let jsonData = NSData(contentsOfURL:filePath!)
let json = JSON(data: jsonData!, options: NSJSONReadingOptions.AllowFragments, error: nil)
for (key: String, subJson: JSON) in json {
var language:String?, link: String?, description:String?, greetingText: String?
for (key1, value:JSON) in subJson {
switch key1 {
case "briefDes": language = value.string
case "skill": link = value.string
case "userId": description = value.string
case "id": greetingText = value.string
default: break
}
}
let greeting = initTable(language: language, link: link, description: description, greetingText: greetingText)
self.greetings.append(greeting)
self.greetings = self.greetings.filter { $0.description == "\(id)"}
}
}
func getGreetingsAsAnyObjects() -> [String: [AnyObject]]{
return [SelectJobConstant.GreetingOBJHandlerSectionKey: greetings.map { $0 as AnyObject }]
} }