Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load data into ViewController from local JSON file [closed]

Tags:

json

ios

local

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?

like image 763
es1 Avatar asked Oct 15 '13 17:10

es1


People also ask

How to access local JSON files in chrome?

No error in console as well : ( Chrome allows you to access local JSON or other data files if you launch it with the --allow-file-access-from-files flag. I checked this with the code above on version 34.0.1847.131 m; it should work on other versions as well.

How to read and parse local JSON data in flutter?

Reading and parsing local JSON data is very simple in Flutter. In fact, it takes just two lines of code to set up access local JSON data as Future async function and make a List for Json Data. In this article, we’re going to see how we can read and parse JSON files locally and show the data in a listview.

How do I read data from a JSON file in node?

3. To read data from the JSON file, we’ll use the getStaticProps () function and the fs Promises API (this is a built-in feature of Node.js so that you don’t have to install any third-party packages). Remove all of the default code in pages/index.js then add the following:

How do I convert a JSON file to JavaScript?

Transform the JSON file into a JavaScript by creating a function that returns the data as JavaScript object. Then you can load it with <script> tag and call the function to get the data you want. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.


1 Answers

You can use NSJSONSerialization for this.

NSError *deserializingError;
NSURL *localFileURL = [NSURL fileURLWithPath:pathStringToLocalFile];
NSData *contentOfLocalFile = [NSData dataWithContentsOfURL:localFileURL];
id object = [NSJSONSerialization JSONObjectWithData:contentOfLocalFile 
                                            options:opts 
                                              error:&deserializingError];
like image 94
matehat Avatar answered Oct 04 '22 15:10

matehat