JSON String to NSDictionary with Swift

后端 未结 3 1611
孤城傲影
孤城傲影 2021-02-09 01:50

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:44

    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)")
    }
    

提交回复
热议问题