Swift 4 decode simple root level json value

前端 未结 2 428
猫巷女王i
猫巷女王i 2020-12-03 17:38

According to the JSON standard RFC 7159, this is valid json:

22

How do I decode this into an Int using swift4\'s decodable? This does not w

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 18:11

    In iOS 13.1+ and macOS 10.15.1+ JSONDecoder can handle primitive types on root level.

    See the latest comments (Oct 2019) in the linked article underneath Martin's answer.

提交回复
热议问题