简体   繁体   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"
  }
}

I need to store the product name inside of a struct but don't know how to access it within the '0'.我需要将产品名称存储在结构中,但不知道如何在“0”中访问它。 This is my attempt below:这是我在下面的尝试:

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"
  }
}

I need to store the product name inside of a struct but don't know how to access it within the '0'.我需要将产品名称存储在结构中,但不知道如何在“0”中访问它。 This is my attempt below:这是我在下面的尝试:

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