2017-03-16 136 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

相關問題