Created
February 27, 2021 01:04
-
-
Save StewartLynch/66f54907d702a6275e25ff87809af281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct SalesForce: Codable { | |
struct Records: Codable { | |
struct Attributes: Codable { | |
let type: String | |
let url: String | |
} | |
let attributes: Attributes | |
let name: String | |
let id: String | |
let rtmsCityLaneC: String | |
let rtmsOfferRateC: Double | |
let rtmsExpectedShipDate2C: String | |
let originCityStateC: String | |
private enum CodingKeys: String, CodingKey { | |
case attributes | |
case name = "Name" | |
case id = "Id" | |
case rtmsCityLaneC = "rtms__City_Lane__c" | |
case rtmsOfferRateC = "rtms__Offer_Rate__c" | |
case rtmsExpectedShipDate2C = "rtms__Expected_Ship_Date2__c" | |
case originCityStateC = "Origin_City_State__c" | |
} | |
} | |
let totalSize: Int | |
let done: Bool | |
let records: [Records] | |
} | |
let JSONString = """ | |
{ | |
"totalSize":1, | |
"done":true, | |
"records":[ | |
{ | |
"attributes":{ | |
"type":"rtms__Load__c", | |
"url":"/services/data/v42.0/sobjects/rtms__Load__c/a0j5b00000Lit4FAAR" | |
}, | |
"Name":"385332", | |
"Id":"a0j5b00000Lit4FAAR", | |
"rtms__City_Lane__c":"SAVANNAH, GA: CONCORD, NC", | |
"rtms__Offer_Rate__c":700.0, | |
"rtms__Expected_Ship_Date2__c":"2021-02-26", | |
"Origin_City_State__c":"SAVANNAH, GA" | |
} | |
] | |
} | |
""" | |
func decodeData() { | |
let decoder = JSONDecoder() | |
guard let data = JSONString.data(using: .utf8), | |
let salesForceObject = try? decoder.decode(SalesForce.self, from: data) else { return } | |
let record = salesForceObject.records[0] | |
print(""" | |
\(record.name) | |
\(record.id) | |
\(record.rtmsCityLaneC) | |
\(record.rtmsOfferRateC) | |
\(record.rtmsExpectedShipDate2C) | |
\(record.originCityStateC) | |
""") | |
} | |
decodeData() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment