/ / Lokale JSON-Datei mit SwiftyJSON lesen - json, swift, swifty-json

Lokale JSON-Datei mit SwiftyJSON lesen - json, swift, swifty-json

und ich wollte meine "data.json" lesen, die sich im Ordner "Supporting Files" befindet.
Aber ich bin verwirrt, weil viele der Tutorials entweder schnell 1.0 sind oder nicht zeigen, wie es mit einer lokalen Datei gemacht wird.

Kann mir jemand helfen ?

So weit bin ich gekommen:

    if let path = NSBundle.mainBundle().pathForResource("data", ofType: "json") {
if let data = NSData(contentsOfMappedFile: path) {
let json = JSON(data: data, options: NSJSONReadingOptions.AllowFragments, error: nil)
println("jsonData:(json)")
}
}

Ich bekomme auch eine Warnung, dass "contentsOfMappedFile" veraltet ist.

Ich versuchte es für 20 Minuten, konnte es nicht zur Arbeit bringen :(

Antworten:

6 für die Antwort № 1

weil init(contentsOfMappedFile:) ist in iOS8 veraltet.

Du solltest das also ändern

data = NSData(contentsOfMappedFile: path)

zu

data = NSData(contentsOfFile: path)