ios - 在 iOS Swift 中将 NSDistionary 转换为 Json 的问题

标签 ios json swift

NSDictionary 将 Json 中的 Bool 值转换为 0 或 1 有没有办法将 Json 属性的值设置为 true 或 false

喜欢 { gender : true },但不喜欢 { gender : 1 }

最佳答案

0 或 1 将被 NSJSONSerialization 解析为 NSNumber

您可以在 NSNumber 上访问 boolValue

这是一些伪swift

let number:NSNumber = dict['gender']

let boolValue = number.boolValue

关于ios - 在 iOS Swift 中将 NSDistionary 转换为 Json 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28438573/

相关文章:

ios - Swift 实例成员问题

iphone - 通过 tableview 添加 View (UITableViewController)

ios - Apple Watch 控制台/设备日志为空

c# - 有条件地将不同的 json 属性反序列化为相同的模型属性

ios - OpenEars 语音识别将其他单词检测为正确单词

ios - 如何使用 SwiftAddressBook 操作 iOS 联系人?

iphone - 确定 iPhone 的大致位置

iOS:outputStream 不会保持打开状态

ruby-on-rails - js 中的 Rails : how to render an other action in the controller, 不是 html?

java - 如何让Spring Boot的GET返回JSON