gpt4 book ai didi

swift - 限制从 Swift 中的 Deployd 查询返回的对象

转载 作者:行者123 更新时间:2023-11-30 10:12:21 24 4
gpt4 key购买 nike

我使用 Deployd 作为我的 Swift 应用程序的后端。这就是我当前查询 JSON 数据的方式。我需要限制从查询返回的对象的数量。我将自己实现分页部分。我只是想知道如何在查询中嵌入下面提到的 $limit 方法。任何建议将不胜感激。

http://docs.deployd.com/docs/collections/reference/querying-collections.html#s- $limit-1416

来自 Deployd 的文档:

The $limit command allows you to limit the amount of objects that are returned from a query. This is commonly used for paging, along with $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 }]
} }

最佳答案

这就是我让它工作的方法:)

Alamofire.request(.GET, "http://localhost:2403/postedjob", parameters: ["$limit": 2, "$sort": ["userId":"-1"]])
.responseJSON { _, _, JSON, _ in
println(JSON)
}

关于swift - 限制从 Swift 中的 Deployd 查询返回的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32241615/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com