'how to get "@microsoft.graph.downloadUrl" from json because @ is a keyword and canno be used for variables. @microsoft.graph.downloadUrl cant declare
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 @
Solution 1:[1]
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"
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MBT |
