如何从json对象获取我的列表数据,如下所示:
users: {
uid: {
name: "user1",
items: {
itemID1: {
name: "item1"
},
itemID2: {
name: "item2"
}
}
}
}
如何获取此项列表并将其与MVVM结构一起使用。我尝试做同样的事情,这篇文章与朋友一起做。但我正在使用firebase来加载数据。
https://medium.com/@stasost/ios-how-to-build-a-table-view-with-multiple-cell-types-2df91a206429
谢谢您的帮助!
如果您想为不同的用户显示不同的单元格,并且需要使用单元格注册进行字符串枚举,然后切换它们,这取决于您想要的内容。我想你不想回答如何解析JSON。
对于本文,您需要填写看起来像这样的数据模型
class Profile {
var fullName: String?
var pictureUrl: String?
var email: String?
var about: String?
var friends = [Friend]()
var profileAttributes = [Attribute]()
}
class Friend {
var name: String?
var pictureUrl: String?
}
class Attribute {
var key: String?
var value: String?
}
所以你需要这样的数据
users: {
uid: {
fullName: "user1",
pictureUrl: "svff",
email: "[email protected]",
about: "Hello, world!",
friends: {
0: {
name: "Jon",
pictureUrl : "dfbdvsd"
},
1: {
name: "Tyrion",
pictureUrl : "dfbdvsd"
}
},
attributes: {
0: {
key: "key1",
value : "value1"
},
1: {
key: "key2",
value : "value2"
}
}
}
}