Last.fm 似乎在其 JSON API 的一些变量名称前面放置了 #
符号。查看示例响应 此处。当我尝试使用 JavaScript 访问 #text
时,我在控制台中收到无效符号错误。有什么快速修复方法或此哈希的原因吗?
Last.fm seems to put #
symbols in front of some of their variable names for it's JSON API. Have a look at a sample response here. As soon as I try and access #text
with JavaScript I get an invalid symbol error in the console. Any quick fixes or reasons for this hash?
发布评论
评论(1)
jQuery 仅用于检索数据。访问
#text
数据是通过直接的 JavaScript 语法完成的,例如data.recenttracks.track.artist["#text"]
你不能这样做
artist .#text
,因为#
是用于访问对象成员的无效第一个字符符号。请改用方括号。jQuery is only used to retrieve the data. Accessing the
#text
data is done through straight JavaScript syntax, something likedata.recenttracks.track.artist["#text"]
You can't do
artist.#text
, because#
is an invalid first character symbol to be used for accessing an object member. Use the square brackets instead.