2015-10-05 78 views
0

我想從我的Deployd API與alamofire查詢數據。如何在請求中進行比較?我有類似的東西:Deployd比較和alamofire swift

let parameters = ["number": ["gt": 3]] 
Manager.sharedInstance.request(.GET, "http://localhost:2403/collections", parameters: parameters).responseJSON { (request, response, result) -> Void in 
      print(result.isSuccess) 
      print(result.data) 
     } 

但結果是空的。在我的儀表板中,我有一個數值列:1,2,3和4.因此,響應應該返回數字4的行。

任何想法? 謝謝

回答

0

您需要提取value而不是data。在Alamofire 2.0中,data僅在.Failure的情況下可用。這一切都是在Alamofire 3.0中重新設計的,它利用了一個Response對象。

let parameters = ["number": ["gt": 3]] 
let URLString = "http://localhost:2403/collections" 

Manager.sharedInstance.request(.GET, URLString, parameters: parameters) 
    .responseJSON { (request, response, result) -> Void in 
     print(result.isSuccess) 
     print(result.data) 
     print("JSON: \(result.value)") 
     print("Error: \(result.error)") 
    } 
+0

它沒有工作。控制檯不打印任何東西,JSON:可選(()) – emoleumassi

+0

然後你需要打印出錯誤。這應該給你更多的信息。另外,我剛剛注意到,當使用'.PUT'或'.POST'時,使用'.GET'會更有意義。 – cnoon

+0

使用.PUT還是.POST?文檔建議使用GET來完成。請參閱http://docs.deployd.com/docs/collections/reference/querying-collections.html#s-$skip-1416。我用POST嘗試它,但我得到一個錯誤:JSON:可選({=「必須提供id來更新對象」; status = 400; })。使用GET,錯誤爲零 – emoleumassi