Last.fm api 和 &特点
var artist = 'Marina & the Diamonds';
var infourl = 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist='+artist+'&api_key=xxx&format=json&callback=?';
这是我的 javascript 代码,我使用 infourl 进行 getJson 查询。但正如您所看到的,artist 变量有一个 &
字符,last.fm api 返回名为 Marina 的艺术家,而不是 Marina & 。钻石。同时,该网址似乎没问题:
Request URL:http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Marina%20&%20the%20Diamonds&api_key=xxx&format=json&callback=jsonp1301591978245
有什么想法吗?谢谢
var artist = 'Marina & the Diamonds';
var infourl = 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist='+artist+'&api_key=xxx&format=json&callback=?';
This is my javascript code, and i use the infourl for a getJson query. But as you can see, the artist variable has a &
character, and the last.fm api is returning the artist called Marina, not Marina & the Diamonds. Meanwhile, the url seems to be fine:
Request URL:http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Marina%20&%20the%20Diamonds&api_key=xxx&format=json&callback=jsonp1301591978245
Any idea? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
URL 将
&
编码为&
。它应该是
%26
。使用
encodeURIComponent("Marina & the Diamonds")
对查询字符串参数进行编码。The URL has
&
as encoded&
.It should be
%26
.Use
encodeURIComponent("Marina & the Diamonds")
to encode the query string parameters.