I am trying to access ["upper category"]["first category"][0][0] of local json file
{
"upper category": {
"first category": [
[
"this is a question",
"this is an answer",
"this is the rank"
],
[
"this is a question2",
"this is an answer2",
"this is the rank2"
]
],
"second category": [
[
"this is a question3",
"this is an answer3",
"this is the rank3"
]
]
}
}
with
let path = Bundle.main.path(forResource: "data", ofType: "json")
do {let data:NSData = try NSData(contentsOfFile: path!)
let json = try? JSONSerialization.jsonObject(with: data as Data, options: JSONSerialization.ReadingOptions.mutableContainers) as AnyObject
I am not able to access anything beyond the first dictionary.
I tried several times with options like (I tried multiple older solutions but they don't seem to work for me, maybe swift 3)
if let description = ((((json?["upper category"] as? AnyObject)?["first category"] as? AnyObject)?[0] as? AnyObject)?[0] as? String) {
It is likely a noob question, I am new to ios. While any answer extremely appreciated explaining how to write code for other number of nested types would be best
(xcode 8, swift 3)