Closed MuRanJiangXia closed 5 years ago
现在框架内部会自动过滤NSNull,我加个单元测试上去
struct Cat: Convertible {
var weight: Double = 0.0
var name: String = "xx"
var data: NSNull?
}
let json: [String: Any] = [
"name": NSNull(),
"weight": 6.6,
"data": NSNull()
]
let cat = json.kj.model(Cat.self)
// convert failed, keep default value
XCTAssert(cat?.name == "xx")
XCTAssert(cat?.weight == 6.6)
XCTAssert(cat?.data == NSNull())
如果你是用pod,可以重新装一下KakaJSON
Pods/KakaJSON
文件夹rm -rf ~/Library/Caches/CocoaPods/Pods/Release/KakaJSON
pod install
恩恩 可以了。
如果接口返回 为null
就需要这样处理了,有没有规避null 的处理呢?不想每个属性都加个判断,这样很麻烦呀。