如何在循环中获取xml解析值

时间:2019-03-16 12:45:35

标签: javascript jquery json

在这里,我想获取(循环)从响应到var数据data1的纬度和经度数。 帮我解决这个问题...

响应:

{"Last30PointsDataJSon":[{"Latitude":11.766470,"Longitude":77.884158,"Speed":11.00,"PositionTime":"16/Mar/2019 04:32:32 PM","PositionType":"GPS","Direction":"NorthWest","ACC":"Off","Battery":"100%","GSMStrength":"Strong Signal","PowerStatus":"Power Connected"},{"Latitude":11.766087,"Longitude":77.884393,"Speed":35.00,"PositionTime":"16/Mar/2019 04:32:22 PM","PositionType":"GPS","Direction":"NorthWest","ACC":"Off","Battery":"100%","GSMStrength":"Strong Signal","PowerStatus":"Power Connected"},{"Latitude":11.765148,"Longitude":77.884998,"Speed":45.00,"PositionTime":"16/Mar/2019 04:32:12 PM","PositionType":"GPS","Direction":"NorthWest","ACC":"Off","Battery":"100%","GSMStrength":"Strong Signal","PowerStatus":"Power Connected"}]}

var txt = '<?php echo $response;?>' //here,I got the Json response (above response)
var parser, xmlDoc;
parser = new DOMParser();
xmlDoc = parser.parseFromString(txt,"text/xml");
var data = xmlDoc.getElementsByTagName("Latitude")[0].childNodes[0].nodeValue;
var data1 = xmlDoc.getElementsByTagName("Longitude")[0].childNodes[0].nodeValue;
console.log(data,',',data1);
var locations=[
[data,data1]
];

0 个答案:

没有答案