Today’s tutorial comes to you courtesy of Brian Burton, Corona Ambassador and author of “Mobile App Development with Corona: Getting Started.” This tutorial was originally published on Burton’s Media Group.
A question that I am regularly asked is how to get data from a remote server (usually stored in a database) into a mobile app.
I wrestled with how best to present this information: whether it should be a series, how many different methods I should include, etc. There are so many variations and possibilities, the task would likely never be finished. So, rather than leave this idle for another couple of months, here is a tutorial on at least one approach to get data from a remote server into a mobile app.
I went with a standard 3-tier architecture to keep things simple.
For this tutorial, I created a MySQL database on a remote server. It has just one table with 3 fields: id, Movie (title), and the Year the movie was released.
Logic or Middleware
I use php for the middleware to pull the data from the MySQL database and encode it into the JSON format before returning it to the mobile device:
This is the Corona code that I use to pull the information from the remote server, decode the JSON formatted information, save it to a local SQLite file then load the contents of the SQLite file onto the screen. Note that the database is persistent, so if you run it multiple times, the remote database call will continue to add new rows of data to the SQLite database.
And that wraps up the basics of the tutorial! For a detailed video explanation, check out the YouTube video:
27 Responses to “How to Download JSON Data From MySQL Using Corona”