2017-03-16 128 views
1

我需要的JSONOBJECT.routingpath.coordinates.length 我得到这个网址的响应长度。我怎样才能得到一个RESPONSABLE URL的长度在JavaScript

http://193.70.60.44:3000/taxi_server/api/v1.0/taxiroute

从服务器响应...

[{ 
    "idtaxiroute": "3", 
    "routingpath": { 
     "type": "LineString", 
     "coordinates": [ 
      [49.9670749, 7.8994591], 
      [49.9682897, 7.898872900000001], 
      [49.9682897, 7.898872900000001], 
      [49.9680662, 7.897596899999999], 
      [49.9680662, 7.897596899999999], 
      [49.9689168, 7.897404499999999], 
      [49.9689168, 7.897404499999999], 
      [49.9690376, 7.895451], 
      [49.9690376, 7.895451], 
      [49.9688003, 7.891565000000001], 
      [49.9688003, 7.891565000000001], 
      [49.966386, 7.888530899999999], 
      [49.966386, 7.888530899999999], 
      [49.9651325, 7.8884534], 
      [49.9651325, 7.8884534], 
      [49.9411728, 7.912222499999999], 
      [49.9411728, 7.912222499999999], 
      [49.9391022, 7.9152532], 
      [49.9391022, 7.9152532], 
      [49.9337381, 7.9157891], 
      [49.9337381, 7.9157891], 
      [49.9241653, 7.829844099999999], 
      [49.9241653, 7.829844099999999], 
      [49.9259564, 7.8275102], 
      [49.9259564, 7.8275102], 
      [49.922877, 7.8259417], 
      [49.922877, 7.8259417], 
      [49.92355939999999, 7.8055037], 
      [49.92355939999999, 7.8055037], 
      [49.9258713, 7.8004553], 
      [49.9258713, 7.8004553], 
      [49.9262293, 7.7978919], 
      [49.9262293, 7.7978919], 
      [49.92596469999999, 7.795387600000001], 
      [49.92596469999999, 7.795387600000001], 
      [49.9216437, 7.7577913], 
      [49.9216437, 7.7577913], 
      [49.91755209999999, 7.7473702], 
      [49.91755209999999, 7.7473702], 
      [49.9107566, 7.726173299999999], 
      [49.9107566, 7.726173299999999], 
      [49.9115306, 7.725327200000001] 
     ] 
    }, 
    "taxiid": 551, 
    "riderequestid": 7 
}, { 
    "idtaxiroute": "4", 
    "routingpath": { 
     "type": "LineString", 
     "coordinates": [ 
      [49.9670749, 7.8994591], 
      [49.9670378, 7.899477099999999], 
      [49.9670378, 7.899477099999999], 
      [49.9651449, 7.898171800000001], 
      [49.9651449, 7.898171800000001], 
      [49.9645179, 7.894035400000001], 
      [49.9645179, 7.894035400000001], 
      [49.9605222, 7.893961699999999], 
      [49.9605222, 7.893961699999999], 
      [49.95326799999999, 7.902490999999999], 
      [49.95326799999999, 7.902490999999999], 
      [49.9518747, 7.9065943], 
      [49.9518747, 7.9065943], 
      [49.9495675, 7.907795699999999], 
      [49.9495675, 7.907795699999999], 
      [49.9479066, 7.9125997], 
      [49.9479066, 7.9125997], 
      [49.9405005, 7.910934200000001], 
      [49.9405005, 7.910934200000001], 
      [49.9400513, 7.9114172] 
     ] 
    }, 
    "taxiid": 551, 
    "riderequestid": 7 
}] 

代码:

for(var i = 0; i < JSONOBJECT[i].routingpath.length; i++) 
    { 
     console.log("Type: " + JSONOBJECT[i].routingpath.coordinates[i][i]); 
    console.log("Types: " + i); 
    } 

你能帮助我吗?

+0

您确切的要求是什么......? – user7417866

+0

我想与坐标的循环和的OpenLayers绘制折线,为此我需要的坐标的长度的长度为循环 –

回答

1

使用JSONOBJECT[i]来计算使用ifor循环的限制是没有意义的。

您需要嵌套循环,一个用于JSONOBJECT阵列,另一个用于coordinates

for (var i = 0; i < JSONOBJECT.length; i++) { 
    var coords = JSONOBJECT[i].routingpath.coordinates; 
    for (var j = 0; j < coords.length; j++) { 
     console.log("Type: " + coords[j]); 
    } 
} 
+0

正是你需要这个... – user7417866

相关问题