2015-10-05 61 views
0

對不起,如果這是一個經常性問題,但我找不到任何好的答案。AFNetworking和JSON參數

使用AFNetworking和SwiftyJSON。

我需要這樣做:

let locationJArray = JSON(myLocationArray) 

    let params = [ 
     "deviceID" : deviceID 
     ,"deviceAPIKey" : deviceAPIKey 
     ,"location" : locationJArray 
    ] 

locationJArray內容:

[ 
    { 
    "theDirection" : -1, 
    "latitude" : -22.90354, 
    "longitude" : -43.20959, 
    "theAccuracy" : 5, 
    "theSpeed" : -1 
    } 
] 

錯誤:

Type of expression is ambiguous without more context

當我試圖通過locationJArray到PARAMS值

相反,使用myLocationArray直接參數值作品,但數據完全無法被api讀取。

PARAMS內容使用myLocationArray:

["deviceID": 68, "location": (
     { 
     latitude = "-22.90354"; 
     longitude = "-43.20959"; 
     theAccuracy = 5; 
     theDirection = "-1"; 
     theSpeed = "-1"; 
    } 
), "deviceAPIKey": a4465be43ec2b4c3baa50d2ca5ee2be8] 

我怎麼能傳遞一個參數值作爲JSON?

回答

0

對於那些有同樣的問題:

let locationJArray = String(JSON(myLocationArray)) 

let params = [ 
    "deviceID" : deviceID 
    ,"deviceAPIKey" : deviceAPIKey 
    ,"location" : locationJArray 
] 

鑄造JSON對象作爲字符串來解決這個問題。