2016-05-16 134 views
-1

有人可以幫助我從中提取緯度和變量嗎?Json解析變量

url  : http://something.com/rest/items/location1?type=json 
data : {} 

'URL' 輸出這個結果

{"type":"LocationItem","name":"location1","state":"9.4702741,-76.5070072","link":"http://something/rest/items/location1"}, 
+1

您使用什麼語言來解析JSON? – Daryl

+0

這些變量在javascript –

回答

0

看起來它已經被返回的JSON對象 - 無需解析需要。你只需要用逗號分割狀態並獲得兩個經緯度。以此爲例:

var myOutput = {"type":"LocationItem","name":"location1","state":"9.4702741,-76.5070072","link":"http://something/rest/items/location1"}; 
var state = myOutput.state; 
var splitState = state.split(','); 
var latitude = splitState[0]; 
var longitude = splitState[1]; 
console.log("Latitude: " + latitude); 
console.log("Longitude: " + longitude); 
+0

裏面非常感謝,對我很有用。 –