I get respose in json n-array tree. I’ve to show one object at a time following is the api response I get .
{
"standing" : true,
"code" : 200,
"outcomes" : [
{
"choice" : null,
"assessment" : 133,
"id" : 863,
"title" : "What do you like to eat duing a movie?",
"choices" : [
{
"id" : 1738,
"title" : "Popcorn",
"nas_class" : "c1",
"question" : 863,
"questions" : [
{
"choice" : 1738,
"assessment" : 133,
"id" : 864,
"title" : "What flavours of popcorn do you like?",
"choices" : [
{
"id" : 1739,
"title" : "Caramel",
"nas_class" : "c1",
"question" : 864,
"questions" : [
]
},
{
"id" : 1740,
"title" : "Cheese",
"nas_class" : "c1",
"query" : 864,
"questions" : [
]
},
{
"id" : 1741,
"title" : "Tomato",
"nas_class" : "c1",
"query" : 864,
"questions" : [
]
},
{
"id" : 1742,
"title" : "Chilli",
"nas_class" : "c1",
"query" : 864,
"questions" : [
{
"choice" : 1742,
"assessment" : 133,
"id" : 865,
"title" : "How good is your spice tolerance?",
"choices" : [
],
"description" : "",
"sort" : "score",
"creator" : 5
}
]
}
],
"description" : "",
"sort" : "multi_select",
"creator" : 5
}
]
},
{
"id" : 1743,
"title" : "Nachos",
"nas_class" : "c1",
"query" : 863,
"questions" : [
]
},
{
"id" : 1744,
"title" : "Chips",
"nas_class" : "c1",
"query" : 863,
"questions" : [
]
}
],
"description" : "",
"sort" : "single_select",
"creator" : 5
},
{
"selection" : null,
"evaluation" : 133,
"id" : 866,
"title" : "Describe the sort of tales you get pleasure from watching",
"selections" : [
],
"description" : "",
"sort" : "free_text",
"creator" : 5
},
{
"selection" : null,
"evaluation" : 133,
"id" : 867,
"title" : "Signal right here to point that you just consent promoting of your knowledge",
"selections" : [
],
"description" : "",
"sort" : "signature",
"creator" : 5
},
{
"selection" : null,
"evaluation" : 133,
"id" : 868,
"title" : "Add an image of your driving license",
"selections" : [
],
"description" : "",
"sort" : "file_upload",
"creator" : 5
},
{
"selection" : null,
"evaluation" : 133,
"id" : 869,
"title" : "Give your opinion",
"selections" : [
{
"id" : 1745,
"title" : "Bad",
"nas_class" : "c1",
"question" : 869,
"questions" : [
]
},
{
"id" : 1746,
"title" : "Poor",
"nas_class" : "c1",
"query" : 869,
"questions" : [
]
},
{
"id" : 1747,
"title" : "Good",
"nas_class" : "c1",
"query" : 869,
"questions" : [
]
},
{
"id" : 1748,
"title" : "Glorious",
"nas_class" : "c1",
"query" : 869,
"questions" : [
]
}
],
"description" : "",
"sort" : "single_select",
"creator" : 5
}
],
"msg" : "Success"
}
func preorderTraversalDFS(_ roots: [ResultsQuestions]?) -> [Int: TreeItem] {
guard let roots = roots else {
return [:]
}
var end result: [Int: TreeItem] = [:]
for root in roots {
let treeItem = TreeItem(id: root.id,
title: root.title,
description: root.description,
sort: root.sort,
evaluation: root.evaluation,
selections: convertChoices(root.selections),
selection: root.selection,
creator: root.creator)
end result[root.id] = treeItem
if let selections = root.selections {
for selection in selections {
let subTree = preorderTraversalDFS(selection.questions)
subTree.forEach { (key, worth) in
end result[key] = worth
}
}
}
}
arrayDict = end result
return end result
}
I’ve added the picture for the UI.
I’ve tried this hyperlink for the reply :- Transfer collectionView on button click on (Swift). However I’ve nested json construction it’s not working for me. I’ve tried to get the json right into a dictionary.
however it’s not going within the nested tree array construction.