2016-11-03 4 views
0

Ich habe eine NodeJS-API, die einen MongoDB-Cluster abfragt und Daten in der Nähe im folgenden Format zurückgibt. Das Problem ist, dass ich die Orte mit Swift 3 und XCode 8.1 nicht aufzählen kann.GeoJSON-Daten von MongDB in Xcode 8.1 Swift 3 lesen?

[ { "_id": "57b03fa32c6835946afd358c" "location": { "Koordinaten": [ 144,2, -34 ], "Elevation": "1", "type" : "Punkt" }, "name": "Ressourcen 01", "url": "http://www.url.com/Resource01.html" }, { "_id": "34b03fa32c6835946afd358c", "location": { "Koordinaten": [ 154.2, -35,3 ], "Elevation": "1", "type": "Punkt" }, "name": "Ressourcen 02", "url": "http://www.url.com/Resource02.html" } ]

Dies ist mein Abfragecode.

Ich habe versucht, SwiftyJSON zu verwenden, aber es funktioniert auch nicht?

Antwort

0

Gelöst:

 
if let jsonBranch = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: AnyObject]], 
    let name = jsonBranch?[0]["name"] as? String { 
    print ("name: " + name) 
} 
if let jsonBranch = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: AnyObject]], 
    let name = jsonBranch?[1]["name"] as? String { 
    print ("name: " + name) 
}