2017-04-01 65 views
0

我試圖將數組作爲參數,但結果永遠不會成功。在Alamofire Swift中發送數組作爲參數

這裏是我的參數:

let params: [String: Any] = [ 

     "debug": "1", 
     "check_in": checkIn, 
     "check_out": checkOut, 
     "theme": theme, 
     "beds": Beds, 
     "bedrooms": Bedroom, 
     "bathrooms": Bathroom, 
     "facility": idFacility, 
     "room_type": id, 
     "page": 1, 
     "take": 10, 
     "id_user": sessionId 
    ] 

    print(params) 
    print("THE PARAMS") 

如果我的參數打印:

[ 
"take": 10, 
"page": 1, 
"debug": "1", 
"id_user": 103, 
"theme": [17, 18, 19], 
"check_in": "2017-04-01", 
"check_out": "2017-04-02", 
"bedrooms": 1, 
"beds": 1, 
"room_type": [5, 6, 7], 
"facility": [11, 12, 13], 
"bathrooms": 1] 

我不明白,如果我發送一個字符串或整數它的工作原理。但是,如果數組,response.result.value從來沒有成功。我也嘗試添加[String: Any],但仍然無法正常工作。

+0

上面的例子所創建的字典,而不是陣列。你能展示你期望創造什麼嗎? –

+0

我將值追加到數組並將它們作爲參數發送 –

+0

您能否用相關代碼來解釋一些問題 –

回答

1

我解決它使用:

let params: [String: Any] = [ 

     "debug": "1", 
     "city": city, 
     "check_in": checkIn, 
     "check_out": checkOut, 
     "max_guest": maxGuest, 
     "theme": String(describing: theme), 
     "currency": "IDR", 
     "price_min": priceMinimum, 
     "price_max": priceMaximum, 
     "beds": Beds, 
     "bedrooms": Bedroom, 
     "bathrooms": Bathroom, 
     "facility": String(describing: idFacility), 
     "room_type": String(describing: id), 
     "page": 1, 
     "take": 10, 
     "id_user": sessionId 
    ] 

    print(params) 
    print("THE PARAMS")