我有以下虚拟JSON数据:
{
"folder": {
"id": 1,
"name": "Home",
"parent_folder_id": null,
"num_of_items": 10,
"num_of_items_complete": 10,
"children": {
"folders": [
{
"id": 2,
"name": "Identification",
"num_of_items": 4,
"num_complete": 4
},
{
"id": 3,
"name": "House and Household Equipment",
"num_of_items": 6,
"num_complete": 2
},
{
"id": 4,
"name": "Insurance",
"num_of_items": 4,
"num_complete": 3
},
{
"id": 5,
"name": "Owned Items",
"num_of_items": 6,
"num_complete": 5
}
],
"input_fields": [
{
"id": 1,
"key": "Something",
"value": "Dark Side",
"type": "text"
}
],
"shortcuts": [
]
}
}
}
我需要使用INDEX访问“children”中的每个孩子,而不是通过它的NAME访问collectionView:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.data["folder"]["children"][section].count
}
但它总是为计数返回0。无论如何我能做到吗?
答案 0 :(得分:1)
试试这个:
return self.data["folder"]["children"]["folders"].count
我认为这是你能做到的唯一方法。