Skip to content

a_19. Loading JSON FIles as Objects

fahimc edited this page Mar 21, 2013 · 3 revisions

About

This tutorial will explain how to load a JSON file and then convert the data string into a JSON object.

Load A JSON File

// Use Utensil's URLLoader to load the json file
Utensil.URLLoader.load('example.json',onDataLoadComplete);
},
// this function will take two parameters which will be set by Utensil's URLLoader. First is the raw text     //string and the second is XML (if applicable).
onDataLoadComplete:function(t,x)
{
}

Converting the Data String to an JSON Object

onDataLoadComplete:function(t,x)
{
    // use the eval method to turn the data string into a JSON Object
    var json =eval('(' + t + ')')
}

Clone this wiki locally