Can't parse JSON array with JSONDecoder in Swift 4

前端 未结 1 613
情书的邮戳
情书的邮戳 2021-01-07 01:38

I have a JSON array I need to parse and I choose to use JSONDecoder to parse it.

JSON array looks like this:

[{\"Id\":0,\"Key\":\"key0\",\"Name\":\"n         


        
相关标签:
1条回答
  • 2021-01-07 02:07

    Remove the initial values for the constant properties

    class Result: Codable{
        let title: String
        let id: Int
        let key: String
        let name: String
    
        // ...
    }
    

    (or make the properties variable). Initialized constant properties can not be set by the JSON decoder.

    0 讨论(0)
提交回复
热议问题