在ionic 2 App中过滤掉http请求中不需要的信息

Filter out information that is not required in an http request in ionic 2 App

我想过滤掉 http.get 上不需要的信息,以便将 space 保存在我的 sqlite 数据库中,而且通常不会保存大量我永远不会使用的数据.

http.get

    platform.ready().then(() => {
        this.http.get('https://www.reversegeocoder.com/api/v1/yoursecretapikey/lsd')
        .map(res => res.json())
        .subscribe (data => {
            let lsd_info = data;
            console.log('lsd Fetch', lsd_info);
        });           
    }

来自服务器的响应(可以更大)

[
  {
    "query": "1-6-67-13 W4",
    "response": {
      "status": "ok",
      "err": [],
      "lat": 54.763928,
      "lng": -111.96659,
      "latlngms": "54° 46' 50\" N, 111° 58' 60\" W",
      "country": "Canada",
      "province": "AB",
      "city": "Lac La Biche",
      "street": "9116 95 Street",
      "street_prox": 23,
      "near": {},
      "address": "9116 95 Street, Lac La Biche, AB",
      "lld": "1-SE-6-67-13-4",
      "lsd": "1-6-67-13 W4",
      "lsd_ra": "",
      "uwi": "",
      "nts": "",
      "nts_border": [],
      "utm": "12N 437807E 6068951N",
      "utm_v": "Zone 12, 437807 meters easting, 6068951 meters northing (Northern Hemisphere)"
    }
  }
]

我想过滤掉大部分数据并仅使用 "lat": 54.763928, "lng": -111.96659 作为示例,这样我就可以仅将此信息保存到 sqlite 数据库中。

根据你的代码,我猜是这样的:

platform.ready().then(() => {
    this.http.get('https://www.reversegeocoder.com/api/v1/yoursecretapikey/lsd')
    .map(res => res.json())
    .subscribe (data => {
        let lsd_info = {
            lat: data[0].response.lat,
            lng: data[0].response.lng
        };
        console.log('lsd Fetch', lsd_info);
    });
}

或者这个:

platform.ready().then(() => {
    this.http.get('https://www.reversegeocoder.com/api/v1/yoursecretapikey/lsd')
    .map(res => res.json())
    .map(res => { return { lat: res.response.lat, lng: res.response.lng } })
    .subscribe (data => {
        console.log('lsd Fetch', data);
    });
}