I have a JSON file with this person objects. Each person has different information. This is the structure of the JSON file.
[
{
"person": {
"name": "Dani",
"job": "Artist",
"country": "FR",
"sold": "992",
"email": "Dani",
"facebook": "Artist",
"twitter": "Dani",
"instagram": "Artist",
"snapchat": "Dani",
"photo": "Artist"
}
},
{
"person": {
"name": "Alex",
"job": "",
"country": "TU",
"sold": "992",
"email": "Dani",
"facebook": "Artist",
"twitter": "Dani",
"instagram": "Artist",
"snapchat": "Dani",
"photo": "Artist"
}
}
]
I was able to open the json file but I am not able to parse it. This is my code
func lodData()
{
let data = NSData(contentsOfURL: url!)
do {
let json = try NSJSONSerialization.JSONObjectWithData(data!, options: .AllowFragments)
if let person = json["person"] as? [[String: AnyObject]] {
for p in person {
if let name = p["name"] as? String {
names.append(name)
}
}
}
} catch {
print("error serializing JSON: \(error)")
}
print(names)
}
As result the names array still empty.