Closed neerajkhede16 closed 5 years ago
The reason for this behavior is that JSONSerialization
produces an NSNumber
value for the key "age"
. An NSNumber
value of 1
can be bridged to a Bool
, which is the first type checked in encode(to:)
. See Table 1 in Apple's documentation for NSNumber
.
I believe I've fixed this with f443ddc. Can you please confirm whether this solves your problem?
Yes, this is fixed now. Many thanks for your quick fix.
Please see sample code and its output:
struct People:Codable{ var name:String? var age:Int? }
{"name":"qwertyui","age":1} {"data":{"name":"qwertyui","age":true}}
We can see age value (1) is converted into bool value (true).