[英]Parsing Nested JSON and storing into struct in Swift
{
"0": {
"productname": "Womens Air Jordan 1 Mid \u0027Canyon Rust\u0027 Shoes - Size 7.5W",
"imageurl": "https://www.example.com/",
"producturl": "https://www.example.com/",
"price": "285.00",
"currency": "USD",
"saleprice": "",
"storename": "Google"
}
}
我需要將產品名稱存儲在結構中,但不知道如何在“0”中訪問它。 這是我在下面的嘗試:
struct Shoes: Decodable {
let 0: [ShoeItem];
}
struct ShoeItem: Decodable {
let productname: String
}
{
"0": {
"productname": "Womens Air Jordan 1 Mid \u0027Canyon Rust\u0027 Shoes - Size 7.5W",
"imageurl": "https://www.example.com/",
"producturl": "https://www.example.com/",
"price": "285.00",
"currency": "USD",
"saleprice": "",
"storename": "Google"
}
}
我需要將產品名稱存儲在結構中,但不知道如何在“0”中訪問它。 這是我在下面的嘗試:
struct Shoes: Decodable {
let 0: [ShoeItem];
}
struct ShoeItem: Decodable {
let productname: String
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.