我从 API 得到以下响应:
[
{
"stores": [
{
"store": {
"Name": "A store name",
"City": "NY"
}
},
{
"store": {
"Name": "A second store name",
"City": "ny2"
}
}
]
},
{
"products": [
{
"product": {
"name": "a product",
"price": "1"
}
},
{
"product": {
"name": "a second product",
"price": "2"
}
}
]
}
]
Run Code Online (Sandbox Code Playgroud)
对于两个 JSON 对象(商店和产品),我创建了以下结构:
struct shops_response: Codable {
var stores: [stores]
}
struct products_response: Codable {
var products: [products]
}
struct stores: …Run Code Online (Sandbox Code Playgroud)