this is my first time at swiftlyJSON and I have a problem. I have data in the local json file and I need to take a single object with this file. I used swiftlyjson but I don't know how to parse a file. Now I have an idea to convert the file to a string and this string goes to JSON. I have something like that, thats work, but I'm looking for the easiest way
import Foundation
class TakeDataPropertiesDish{
func parseData(){
var json: String = ""
if let filepath = Bundle.main.path(forResource: "PropertiesDish", ofType: "json") {
do {
json = try String(contentsOfFile: filepath)
} catch {
print("error parse json file to string")
}
}
if let data = json.data(using: .utf8) {
if let json = try? JSON(data: data) {
for item in json["dish"].arrayValue {
print(item["name"].stringValue)
}
}
}
}
}