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?
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.
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.
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:
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.
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];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With