我正在尝试在我使用内置REST API创建的Parse数据库上发出GET请求.当用户在UISearchBar中输入文本时,将进行API调用,最终目标是在UITableView中显示返回的数据.下面的代码仅捕获我尝试发出有效的HTTP请求,我试图查看"Query1"是否与搜索字符串匹配("Query1"是我的Parse数据库中的一个参数,基本上用作关联的搜索词).
//Mark - UISearchBarDelegate
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
makeRequest(searchBar.text)
}
func makeRequest (searchString : String) {
//REST API call to the sampleObjectData class
var request = NSMutableURLRequest(URL: NSURL(string: "https://api.parse.com/1/classes/sampleObjectData")!)
let session = NSURLSession.sharedSession()
request.HTTPMethod = "GET"
//THIS IS MY TROUBLE AREA
var params = urllib.urlencode({"where";:json.dumps({
"Query1": "\(searchString)"
})})
var error: NSError?
request.HTTPBody = NSJSONSerialization.dataWithJSONObject(params, options: nil, error: &error)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
//The kAppId & kRestAPIKey calls are referencing contstants at the top of the file
request.addValue("X-Parse-Application-Id", forHTTPHeaderField: …Run Code Online (Sandbox Code Playgroud)