I'm having trouble accessing the StatusList array from this API response. How would I get that information?
my current code is and does not work.
let parsedData = try JSONSerialization.jsonObject(with: data!) as! [String:Any]
for list in (parsedData["StatusList"] as? [String])!{
for shipmentstatus in list["Details"]{
//doesn't work
}
}
here is the JSON
{
"MobileAPIError":"",
"StatusList":{
"ErrorMessage":"",
"Details":[
{
"Pro":"000000000",
"BlNumber":"000000",
"ReferenceNumber":"",
"Scac":"CNWY",
"Carrier":"XPO LOGISTICS FREIGHT, INC.",
"ShipperCode":"xx999",
"ShipperName":"W B EQUIPMENT",
"ShipperCity":"WOOD RIDGE",
"ShipperState":"NJ"
},
{
"Pro":"0000000",
"BlNumber":"#00000-R",
"ReferenceNumber":"",
"Scac":"CNWY",
"Carrier":"XPO LOGISTICS FREIGHT, INC.",
"ShipperCode":"xx999",
"ShipperName":"W B EQUIPMENT",
"ShipperCity":"WOOD RIDGE",
"ShipperState":"NJ"
},
]
}
}
EDIT: I would like to try to use JSONDecoder, as it looks like a decent solution.
Would this work?
struct ShipmentStatusList: Decodable {
let MobileAPIError: String
let StatusList: StatusListItems
enum CodingKeys : String, CodingKey {
case MobileAPIError
case StatusList
}
}
struct StatusListItems{
let ErrorMessage: String
let Details: [Details]
}
struct Details {
let Pro: String
let BLNumber: String
let ReferenceNumber: String
}