user2105811 user2105811 - 1 year ago 102
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?

Answer Source

You can use NSJSONSerialization for this.

NSError *deserializingError;
NSURL *localFileURL = [NSURL fileURLWithPath:pathStringToLocalFile];
NSData *contentOfLocalFile = [NSData dataWithContentsOfURL:localFileURL];
id object = [NSJSONSerialization JSONObjectWithData:contentOfLocalFile 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download