Get the Json Values from Text File - Swift
func get_json_from_txt_file(fileName: String) -> NSDictionary {
if let path = Bundle.main.path(forResource: fileName, ofType: "txt") {
do {
let str_file_contents = try String(contentsOfFile: path, encoding: .utf8)
let jsonData = str_file_contents.data(using: .utf8)!
let json = try JSONSerialization.jsonObject(with: jsonData, options: []) as! NSDictionary
return json
}
catch {
print(error)
}
}
let dict = NSDictionary()
return dict
}
func get_json_from_txt_file(fileName: String) -> NSDictionary {
if let path = Bundle.main.path(forResource: fileName, ofType: "txt") {
do {
let str_file_contents = try String(contentsOfFile: path, encoding: .utf8)
let jsonData = str_file_contents.data(using: .utf8)!
let json = try JSONSerialization.jsonObject(with: jsonData, options: []) as! NSDictionary
return json
}
catch {
print(error)
}
}
let dict = NSDictionary()
return dict
}
No comments:
Post a Comment