Swift 使用 Alamofire 和 SwiftyJSON 解析 Json [关闭]

Posted

技术标签:

【中文标题】Swift 使用 Alamofire 和 SwiftyJSON 解析 Json [关闭]【英文标题】:Swift using Alamofire and SwiftyJSON to parse Json [closed] 【发布时间】:2016-07-29 08:07:29 【问题描述】:

我尝试使用 SwiftyJSON 从嵌套的 Magento API 中解析 json 数组,其中包含多个类别,并且类别内有多个产品

将产品和类别保存在 mutablearray 中以显示它们的最佳做法是什么

【问题讨论】:

【参考方案1】:

首先,您应该为您的产品创建一个基类,其中将包含有关它们的信息。例如:

struct Product 

    enum ProductType 
        case Women
        case Men
        case Kids
    
    var id : String
    var name : String
    var sku: String
    var type: ProductType

并创建一个Array,其中将包含此对象以进行解析。

var products: [Product]

【讨论】:

好吧,如何在解析中使用这个类 哇,我不会解析你是 json 而不是你我显示方向所以工作

以上是关于Swift 使用 Alamofire 和 SwiftyJSON 解析 Json [关闭]的主要内容,如果未能解决你的问题,请参考以下文章