JSON String to NSDictionary with Swift

后端 未结 3 1444
一生所求
一生所求 2021-02-09 02:11

I am trying to create a dictionary from data that is held in a server, I receive the data but I cannot convert the data to an NSDictionary, I believe it is held in

3条回答
  •  名媛妹妹
    2021-02-09 02:42

    Update for Swift 2.

    Now you must use it inside a try catch block.

        do {
            let responseObject = try NSJSONSerialization.JSONObjectWithData(data, options: []) as! [String:AnyObject]
        } catch let error as NSError {
     print("error: \(error.localizedDescription)")
    }
    

提交回复
热议问题