wie man die Länge des json-kodiertes array in javascript?

Habe ich ein json-kodiertes array wie dieses:

{
  "ar0":"{\"start\":{\"lat\":22.9939202,\"lng\":72.50009499999999},\"end\":{\"lat\":23.0394491,\"lng\":72.51248850000002},\"waypoints\":[[23.0316834,72.4779436]]}",

  "ar1":"{\"start\":{\"lat\":22.9999061,\"lng\":72.65318300000001},\"end\":{\"lat\":23.0420584,\"lng\":72.67145549999998},\"waypoints\":[[23.02237,72.6500747]]}",

  "ar2":"{\"start\":{\"lat\":23.0394491,\"lng\":72.51248850000002},\"end\":{\"lat\":22.9999061,\"lng\":72.65318300000001},\"waypoints\":[[23.0016629,72.58898380000005]]}"

 } 

meine quetion ist :

(1) Wie finden Sie die Länge des Arrays? //here it is 3

(2) Wie es s Wert?
//for example:for as0 the value is {\"start\":{\"lat\":22.9939202,\"lng\":72.50009499999999},\"end\":{\"lat\":23.0394491,\"lng\":72.51248850000002},\"waypoints\":[[23.0316834,72.4779436]]}

javascript code where i use upper things :

 function setroute(os)
{
    var wp = [];
    for(var i=0;i<os.waypoints.length;i++)
        wp[i] = {'location': new google.maps.LatLng(os.waypoints[i][0], os.waypoints[i][1]),'stopover':false }

    ser.route({'origin':new google.maps.LatLng(os.start.lat,os.start.lng),
    'destination':new google.maps.LatLng(os.end.lat,os.end.lng),
    'waypoints': wp,
    'travelMode': google.maps.DirectionsTravelMode.DRIVING},function(res,sts) {
        if(sts=='OK')ren.setDirections(res);
    })  
}

function fetchdata()
{
    var jax = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
    jax.open('POST','process.php');
    jax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');

    jax.send('command=fetch')
    jax.onreadystatechange = function(){ if(jax.readyState==4) {                
    alert(JSON.parse(jax.responseText).ar0);
        try {
                console.log(jax.responseText);

          //it is not work

        for(var i=0;i<JSON.parse(jax.responseText).length;i++) 
                {
                  setroute( eval('(' + jax.responseText + ')') );
                }
            }
        catch(e){ alert(e); }
    }}
}

InformationsquelleAutor DS9 | 2013-10-22

Schreibe einen Kommentar