Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift 3 SwiftyJson get unknown array keys

Im getting json with a variable array key/name. I need to use this name in the app. I have tried let keyINeed = json["venue"][0].arrayObject but i get nil. "Meeting rooms" and "exit" are the values i need to populate a table but i can't hard code them as they can and will change

{  "venue": {
            "name": "Home Office",
            "Meeting rooms": [{
                "name": "1",
                }],
            "exit": [{
                "name": "Back door",
            }]
        }  
}
like image 358
user3550256 Avatar asked Dec 10 '22 14:12

user3550256


2 Answers

ok, so i worked it out for anyone looking to do the same

for (key, value) in json["venue"] {

    print("key \(key) value2 \(value)")

}
like image 187
user3550256 Avatar answered Jan 26 '23 02:01

user3550256


You should use "dictionaryValue":

so now you can do

let data = json["venue"].dictionaryValue
print(data.keys)
like image 44
f0go Avatar answered Jan 26 '23 01:01

f0go