我已经在SO社区的帮助下解析了复杂的JSON,这是参考文献precedence
最后,我得到了这种数据结构:
class Products {
let id: String
var quantities: [(sizeId: String, quantity: String)]?
init(id: String, quantities: [(sizeId: String, quantity: String)]) {
self.id = id
self.quantities = quantities
}
}
它可以很好地保存数据。
这对我来说是一种新方法,就像我以前使用结构一样,但是现在我上课了,我的问题是-稍后如何在应用程序中访问此数据并将其显示给用户?
我已经搜索了结构的标准方法,但是没有运气。 感谢代码示例或有关此问题的任何帮助。谢谢!
答案 0 :(得分:-1)
var new_elements = Products()
then you can access your variables or you can try NSObject for
class Offers: NSObject {
var Offers_Festival_images:String=""
var Offers_title:String=""
var Offers_Slider_images=Array<String>()
var Offers_inner_slider_images=Array<String>()
var Offers_description:String=""
var id:String=""
var date:String = ""
}
for init Value:-
let result:Offers=Offers()
result.Offers_Festival_images=entry["offer_images"].string!
result.Offers_description=entry["Description"].string!
result.Offers_title=entry["Festival_name"].string!
result.date = entry["To_ios_date"].string!
How To access:-
for table view or you can use by using for loop
let offer: Offers = dataArray[indexPath.row] as! Offers