- This topic has 0 replies, 1 voice, and was last updated 11 years, 8 months ago by Brandon.
-
AuthorPosts
-
BrandonMemberOk, so a lot of us want to store information in our app so Im going to show you how to use JSON data in your app and call it back up.
First we need to place in our data, so we will place the following in our custom js file. (for this tutorial screen I am going to use a HTML widget, so you can easily download and run the file without modification).
// Data stored in JSON format var json_obj = {"webcourses": [ {"site": { "categ": "Web Programming", "url": "http://coursesweb.net/php-mysql/", "description": "Free PHP-MySQL online course and tutorials" }}, {"site": { "categ": "Foreign languages", "url": "http://www.marplo.net/engleza/", "description": "Free online English lessons" }}, {"site": { "categ": "Cat three", "url": "http://urlthree/engleza/", "description": "Description three" }}, {"site": { "categ": "cat four", "url": "http://urlfour/engleza/", "description": "descrpt four" }}, {"site": { "categ": "Fifth Catalog", "url": "http://urlFile/engleza/", "description": "Fifth Description" }} ] };
Now that we have established our data we want to be able to pull it up. Assuming we know which record we want to access we could use a simple alert.
alert(json_obj.webcourses[0].site.categ);
This will get our first record with the ‘categ’.
If we don’t know exactly which record we want we can do a simple for loop and look for what we want, in this case we will look for ‘cat four’ and return the url for that record.
for (var i=0;i<json_obj.webcourses.length;i++) { if (json_obj.webcourses[i].site.categ == 'cat four') { alert(json_obj.webcourses[i].site.url); break; } }
Project File: cincyplanet.com/mobione/files/jsonTest.mobi
-
AuthorPosts