Reputation: 39
I am trying to get a JSON array from a JSON file in iOS. The problem is the code is not working The content in JSON file is:
[{a:"m",data:"1597,144",tick:1},{a:"m",data:"1595,144",tick:1}, ...]
This is my Swift code:
if let filePath = NSBundle.mainBundle().pathForResource("data", ofType: "json") {
let array = NSMutableArray(contentsOfFile: filePath)
println("\(array)")
}
The file exists at path but for some reason its not working. I get null
when I try to print the array.
Upvotes: 1
Views: 1961
Reputation: 27335
NSMutableArray(contentsOfFile: filePath)
will only work with property lists:
What you have is JSON string. If you want to load array from JSON file check out this: How do I parse JSON from a file in iOS?
Upvotes: 2