如何从数组中删除引号

How to remove quotes from array

我的本机应用程序尝试放置来自 JSON 的标记。 JSON 数据示例:

{
"status": "ok",
"count": 15,
"count_total": 600,
"pages": 40,

"posts": [
    {
        "ID": "2290",
        "title": "Title",
        "tag": "Tag",
        "lat": "53.11691211703813",
        "lng": "26.03631556034088",
        "thumb": "getImage-24-100x100.jpg",
        "fullimg": "getImage-24.jpg",
        "imgs": [
            {
                "imgurl": "getImage-24-300x200.jpg"
            }
        ],
        "place": "Place",
        "type": "Photo",
        "period": "Period",
        "year": "1985",
        "url": "URL",
        "author": "Author"
    }]}

我的控制器:

        var addressPointsToMarkers = function(points) {
          return points.map(function(ap) {
            return {
              layer: 'realworld',
                lat: ap.lat,
                lng: ap.lng
            };
          });
        };
        $http.get("sample.json").success(function(data) {
            $scope.markers = addressPointsToMarkers(data.posts);
        });

这个returns标记数组,像这样:[{"layer":"realworld","lat":"53.11691211703813","lng":"26.03631556034088 "}]

但我需要从 LAT 和 LNG 坐标中删除引号:[{"layer":"realworld","lat":53.11691211703813,"lng":26.03631556034088}]

您必须将字符串值转换为数字值。您可以通过在它们前面添加一个 + 来实现,如下所示:

return points.map(function(ap) {
  return {
    layer: 'realworld',
    lat: +ap.lat,
    lng: +ap.lng
  };
});

使用JSON.parse().

例如:

return points.map(function(ap) {
  return {
    layer: 'realworld',
    lat: JSON.parse(ap.lat),
    lng: JSON.parse(ap.lng)
  };
});