facebook

In App JSON Data Processing

  1. MobiOne Archive
  2.  > 
  3. Examples, HOW-TOs
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #336904 Reply

    Brandon
    Member

    Ok, 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

Viewing 1 post (of 1 total)
Reply To: In App JSON Data Processing

You must be logged in to post in the forum log in