用Swifty JSON响应填写词典?

时间:2015-02-18 08:58:52

标签: json swift dictionary

我有(swiftyJSON)字符串返回,看起来像:

{
"siteName1" : "http://www.example1.com/",
"siteName2" : "http://www.example2.com/",
"siteName3" : "http://www.example3.com"
}

您如何填写以下字典:

let dictAvailableTracks = [String:String]()

1 个答案:

答案 0 :(得分:1)

从Web服务获取数据后,首先将其序列化为JSON:

let serializedResponse: JSON = JSON(response)

之后你可以得到这样的字典:

let dictAvailableTracks = serializedResponse.dictionaryObject

dictAvailableTracks[String:AnyObject]类型的字典,但您可以将其转换为[String:String]

let dictAvailableTracks = serializedResponse.dictionaryObject as [String:String]