【问题标题】:How do I parse JSON like geo:point?如何解析像 geo:point 这样的 JSON?
【发布时间】:2010-10-31 20:02:04
【问题描述】:

我正在尝试使用来自 last.fm 的 jquery 解析 JSON 响应并获取经度和纬度值。保存这些值的 JSON 部分如下所示:

"location":{"geo:point":{"geo:lat":"58.409901","geo:long":"15.563306"}

我得到的代码是这样的:

$.getJSON("http://ws.audioscrobbler.com/2.0/?method=artist.getevents&artist=familjen&api_key=xformat=json&callback=?",
 function(data){
  $.each(data.events.event, function(i,item){
   $("#menucontent").append("<br/>"+item.title + " " + item.venue.location.geo:point.geo:lat);
        });
});

显然“item.venue.location.geo:point.geo:lat”部分不起作用。如何使用“:”获取这些值?

【问题讨论】:

    标签: jquery json parsing last.fm


    【解决方案1】:

    当标识符不能用dot notation 表示时,您可以使用bracket notation,它看起来像这样:

    item.venue.location["geo:point"]["geo:lat"]
    

    为了说明,所有这些都是访问同一事物的方式:

    obj.thing.prop
    obj.thing["prop"]
    obj["thing"]["prop"]
    obj["thing"].prop
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      • 1970-01-01
      • 1970-01-01
      • 2021-10-22
      • 2011-11-17
      • 2014-07-13
      相关资源
      最近更新 更多