草庐IT

NSdictionary

全部标签

swift - 将 Swift 字典转换为 NSDictionary

我创建了一个SwiftDictionary对象varparams=["first_name":firstNameTextField.text,"last_name":lastNameTextField.text,"company":companyTextField.text,"email_address":emailTextField.text,"phone_number":phoneTextField.text]接下来,我将ObjC框架连接到我的Swift应用程序。里面有个对象有属性@property(nonatomic,retain)NSMutableDictionary*fiel

ios - 使用 Swift 将 JSON 字符串转为 NSDictionary

我正在尝试根据保存在服务器中的数据创建字典,我收到了数据但无法将数据转换为NSDictionary,我相信它保存在中NSData对象letJSONDictionary:Dictionary=NSJSONSerialization.JSONObjectWithData(JSONData!,options:nil,error:&error)asNSDictionary这行代码给我带来了问题,它抛出一个BAD_EXEC_INSTRUCTION。我的问题:如何将JSON转换为NSDictionary? 最佳答案 您的代码没有进行任何错误处理

ios - 使用 Swift 将 JSON 字符串转为 NSDictionary

我正在尝试根据保存在服务器中的数据创建字典,我收到了数据但无法将数据转换为NSDictionary,我相信它保存在中NSData对象letJSONDictionary:Dictionary=NSJSONSerialization.JSONObjectWithData(JSONData!,options:nil,error:&error)asNSDictionary这行代码给我带来了问题,它抛出一个BAD_EXEC_INSTRUCTION。我的问题:如何将JSON转换为NSDictionary? 最佳答案 您的代码没有进行任何错误处理

ios - 从 Objective-C 访问 Swift 扩展

我无法从objective-c访问我的swift扩展。我在.swift文件中有以下代码:extensionNSDictionary{funcdictionaryAsJsonString()->NSString{varerr:NSError?vardata=NSJSONSerialization.dataWithJSONObject(self,options:NSJSONWritingOptions.PrettyPrinted,error:&err)varstring=NSString(data:data,encoding:NSUTF8StringEncoding)returnstrin

ios - 从 Objective-C 访问 Swift 扩展

我无法从objective-c访问我的swift扩展。我在.swift文件中有以下代码:extensionNSDictionary{funcdictionaryAsJsonString()->NSString{varerr:NSError?vardata=NSJSONSerialization.dataWithJSONObject(self,options:NSJSONWritingOptions.PrettyPrinted,error:&err)varstring=NSString(data:data,encoding:NSUTF8StringEncoding)returnstrin

ios - swift 错误 : Reference to generic type Dictionary requires arguments in <. ..>

错误ReferencetogenerictypeDictionaryrequiresargumentsin出现在函数的第一行。我试图让函数返回从api检索到的NSDictionary。有人知道这里会发生什么吗?classfuncgetCurrentWeather(longitude:Float,latitude:Float)->Dictionary?{letbaseURL=NSURL(string:"https://api.forecast.io/forecast/\(apikey)/")letforecastURL=NSURL(string:"\(longitude),\(latit

ios - swift 错误 : Reference to generic type Dictionary requires arguments in <. ..>

错误ReferencetogenerictypeDictionaryrequiresargumentsin出现在函数的第一行。我试图让函数返回从api检索到的NSDictionary。有人知道这里会发生什么吗?classfuncgetCurrentWeather(longitude:Float,latitude:Float)->Dictionary?{letbaseURL=NSURL(string:"https://api.forecast.io/forecast/\(apikey)/")letforecastURL=NSURL(string:"\(longitude),\(latit

json - 字典到 JSON 在 swift 3 中被序列化两次

我正在尝试使用以下已转换为JSON的字典发出发布请求letstore=["newTask":["project_name":"iOS","total_time":0,"color":"blue"]]我使用以下代码对此进行序列化,然后使用以下选项发出http-POST请求:letjsonData=try?JSONSerialization.data(withJSONObject:store)varrequest=URLRequest(url:URL(string:"http://localhost:3000/store")!)request.httpMethod="POST"reques

json - 字典到 JSON 在 swift 3 中被序列化两次

我正在尝试使用以下已转换为JSON的字典发出发布请求letstore=["newTask":["project_name":"iOS","total_time":0,"color":"blue"]]我使用以下代码对此进行序列化,然后使用以下选项发出http-POST请求:letjsonData=try?JSONSerialization.data(withJSONObject:store)varrequest=URLRequest(url:URL(string:"http://localhost:3000/store")!)request.httpMethod="POST"reques

ios - 无法将类型 '__NSArrayM' (0x34df0900) 的值转换为 'NSDictionary' SWIFT

当解码来自网络服务的JSON响应时,我收到一条错误消息:Couldnotcastvalueoftype'__NSArrayM'(0x34df0900)to'NSDictionary'我也尝试了很多在StackOverflow中找到的解决方案,但没有任何效果。我的代码:letjsonData:NSDictionary=(NSJSONSerialization.JSONObjectWithData(urlData!,options:NSJSONReadingOptions.MutableContainers,error:&error)as?NSDictionary)!letsuccess: