Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to parse JSON using PhoneGap

    • 0
    • 3
    • 3
    • 1
    • 0
    • 0
    • 0
    • 0
    • 276
    Comment on it

    Follow the below steps to parse JASON in PhoneGap.

    Step 1. Call Js function From html page or from where we 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);
    
     }
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: