0

我正在使用 SwityJSON 遍历我的 JSON 数据并对其进行解析。它工作正常,但我想确保我正确有效地使用语法。请在下面查看我的代码:

                if let itemDict = json[0]["artists"].dictionaryValue {
                    for item in itemDict {
                        if let artist: Dictionary? = item.1.dictionaryValue {
                            // artist id
                            if let artistId = artist?["id"] {
                                if artistId.stringValue != nil {
                                    // add value to object
                                }
                            }
                            // title
                            if let title = artist?["title"] {
                                if title.stringValue != nil {
                                    // add value to object
                                }
                            }
                            // subtitle
                            if let subtitle = artist?["subtitle"] {
                                if subtitle.stringValue != nil {
                                    // add value to object
                                }
                            }
                            // image url
                            if let imageURL = artist?["imageURL"] {
                                if imageURL.stringValue != nil {
                                    // add value to object
                                }
                            }
                        }
                    }
                }
4

1 回答 1

0

这对所有人来说都是新的,但Ray Wenderlich提供了很好的教程。尝试从中学习。这对我帮助很大。

于 2014-12-06T05:22:33.407 回答