Home > Blockchain >  how to get "@microsoft.graph.downloadUrl" from json because @ is a keyword and canno be us
how to get "@microsoft.graph.downloadUrl" from json because @ is a keyword and canno be us

Time:05-10

import Foundation import UIKit

struct OnedriveItemsData: Decodable {

let value : [Value]

}

struct Value: Decodable {

let name: String
let @microsoft.graph.downloadUrl:String

}

Here @microsoft.graph.downloadUrl cannot be declared and giving error beacuse it starts with @

CodePudding user response:

First give a name of the property like downloadUrl. To match it with server response add the property to CodingKeys enum. For more information please check this.

struct Value: Decodable {
    let name: String
    let downloadUrl: String
    
    private enum CodingKeys: String, CodingKey {
        case name
        case downloadUrl = "@microsoft.graph.downloadUrl"
    }
}
  • Related