Json Parsing Using PhoneGap


Step 1. Call Js function From html page or from where you want like this

function onBodyLoad()
    {        
        document.addEventListener(“deviceready”, callJson, false);
    }
    
    

Step 2.
Create a function of name callJson and call parsing Function from it in js file.

function callJson() {
   
    var webUrl = url;
   //
    check(webUrl);
}

Step 3.

function check(API) {
    alert(“entered”);
    var http_request = new XMLHttpRequest();
    alert(http_request);
    http_request.open(“GET”, API, false);
    http_request.send(null);
    var my_JSON_object = http_request.responseText;
    //alert(my_JSON_object);
    var data = JSON.parse(my_JSON_object);
    alert(data.success);
    if(data.success==true){
    //alert(data.Regions.Region.length);
    var html = ”;
   
        var _length=data.Regions.Region.length;    
        for(var i=0; i<_length;i++){
            var _resort=data.Regions.Region[i];
            var totalResorts=_resort.count;
            var _resionDic={
            name:_resort.name,
            count:totalResorts
            }
            html += ‘<li>  <a href=”#” ></a>’+_resort.name+'</li>’;            
           for(var j=0; j<totalResorts;j++){
                //alert(_resort.Resorts[j].resort_name);
               
               var _resortDic={
               id:_resort.Resorts[j].id,
               name:_resort.Resorts[j].resort_name,
               country:_resort.Resorts[j].country,
               longitude:_resort.Resorts[j].longitude,   
               latitude:_resort.Resorts[j].latitude
               }
               
                _resionDic[“Resort”+i]=_resortDic;
                
                
            }
            Resionlist.push(_resionDic);
        };
        var arr=Resionlist[0];
        var m=0;
        alert(arr[“Resort”+m].name);
        $(“#Region”).html(html);
        $(“#Region”).listview(‘refresh’);
 
    }
}

Best Of Luck.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: