有人可以帮助我从中提取lat和long作为变量吗?
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"},
答案 0 :(得分: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);