javascript - javascript中解析特定格式的Json数组对象

标签 javascript json

我的 JSON 是:

var json = '{"name":"GeoFence","coordinate":[[1,2],[3,4],[5,6]]}',
obj = JSON.parse(json);
alert(obj.coordinate);

但我需要按如下方式设置坐标值:

var myTrip=[new google.maps.LatLng(1,2),new google.maps.LatLng(3,4),new google.maps.LatLng(5,6)];

最佳答案

遍历坐标并为每个坐标创建一个新对象,并将其添加到 myTrip 中:

var myTrip = [];

for(var i=0; i < obj.coordinate.length; i++) {
    myTrip.push(new google.maps.LatLng(obj.coordinate[i][0],obj.coordinate[i][1]))
}

关于javascript - javascript中解析特定格式的Json数组对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21477909/

相关文章:

json - Bitmap Index Scan always Followed by Bitmap Heap Scan for JSON field query

javascript - D3 在 JSON 中获取 JSON 数据

json - Flutter:使用共享首选项插件存储保存的收藏夹列表

javascript - EaselJS:将形状拉伸(stretch)到特定一侧

javascript - 每次组件加载时,Angular 4+ 函数都会重新加载

javascript - REGEX 帮助,= 符号后的变量名称

javascript - 将div附加到页面导致整个页面跳转

javascript - 如何使用 Node 一次安装多个 gulp 包?

java - 如何使用 java 将 json 数组添加到表中以便我可以传递 cookie?

java - 提供 JSON InputStream 的最佳方式