我有一个代码结构
struct FareComponentList: Codable {
let passengerFareInfoList: [PassengerFareInfoList]
let pricingOverview: PricingOverview
}
我想访问PricingOverView元素。
我尝试了几种方法
1)
root.availabilityResultList.first?.availabilityRouteList.first?.availabilityByDateList.first?.originDestinationOptionList.first?.fareComponentGroupList?.first?. pricingOverview
2)
root.availabilityResultList.first?.availabilityRouteList.first?.availabilityByDateList.first?.originDestinationOptionList.first?.fareComponentGroupList?.[0]. pricingOverview
但它总是返回nil
然后我尝试了
let x = root.availabilityResultList.first?.availabilityRouteList.first?.availabilityByDateList.first?.originDestinationOptionList.first?.fareComponentGroupList
taxprice.append(x?.fareComponentList)
给出此错误,类型为'[farecomponentGrouplist]'的价值没有成员'farecomponentList'
如何解决此错误/如何从PripingoverView获取值?
我在这里做错了什么?
您已将其声明为" FareComponentList
",其中具有" PricingOverview
"。但是您正在尝试从其他名称" FareComponentGroupList
"访问" PricingOverview
"。