user2105811 user2105811 - 11 months ago 57
iOS Question

How to load data into ViewController from local JSON file

I'm developing an iPhone app and I need to show stored data in a TableView.
After some research I decided that JSON would be best fit for storing the data. However, I couldn't find any tutorials explaining how to read JSON as a local file rather than
from a remote source, as often is the case.

Any tutorials you could recommend?


You can use NSJSONSerialization for this.

NSError *deserializingError;
NSURL *localFileURL = [NSURL fileURLWithPath:pathStringToLocalFile];
NSData *contentOfLocalFile = [NSData dataWithContentsOfURL:localFileURL];
id object = [NSJSONSerialization JSONObjectWithData:contentOfLocalFile