访问带有哈希 (#) 前缀的 JSON 变量

发布于 2024-10-08 18:51:09 字数 357 浏览 0 评论 0 原文

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

吾家有女初长成 2024-10-15 18:51:09

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 like data.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文