索引处的 SwiftyJSON 项目不起作用
SwiftyJSON Item At Index Not Working
我有以下虚拟 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" 中的每个子项,而不是通过它的 collectionView 名称:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.data["folder"]["children"][section].count
}
但计数总是 returns 0。无论如何我可以做到这一点吗?
试试这个:
return self.data["folder"]["children"]["folders"].count
我认为这是唯一可以做到的方法。
我有以下虚拟 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" 中的每个子项,而不是通过它的 collectionView 名称:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.data["folder"]["children"][section].count
}
但计数总是 returns 0。无论如何我可以做到这一点吗?
试试这个:
return self.data["folder"]["children"]["folders"].count
我认为这是唯一可以做到的方法。