2014-12-06 52 views
0

我正在使用SwityJSON遍歷我的JSON數據並解析它。它工作正常,但我想確保我正確和高效地使用該語法。請仔細閱讀下面我的代碼:用SwiftyJSON解析的正確方法

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

回答

0

這是新的,但所有Ray Wenderlich提供了良好的教程。嘗試從中吸取教訓。這對我幫助很大。