簡體   English   中英

解析嵌套的 JSON 並存儲到 Swift 的結構中

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM