user3550256
user3550256

Reputation: 171

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",
            }]
        }  
}

Upvotes: 4

Views: 3142

Answers (2)

f0go
f0go

Reputation: 272

You should use "dictionaryValue":

so now you can do

let data = json["venue"].dictionaryValue
print(data.keys)

Upvotes: 3

user3550256
user3550256

Reputation: 171

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

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

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

}

Upvotes: 10

Related Questions