2
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 查询。但正如您所见,艺术家变量有一个&字符,并且 last.fm api 返回名为 Marina 的艺术家,而不是 Marina & the Diamonds。同时,网址似乎很好:

Request URL:http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Marina%20&%20the%20Diamonds&api_key=xxx&format=json&callback=jsonp1301591978245

任何的想法?谢谢

4

1 回答 1

5

URL 已&编码&

http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Marina%20&%20the%20Diamonds&api_key=xxx&format=json&callback=jsonp1301591978245

应该是%26

http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Marina%20%26%20the%20Diamonds&api_key=xxx&format=json&callback=jsonp1301591978245

用于encodeURIComponent("Marina & the Diamonds")对查询字符串参数进行编码。

于 2011-03-31T17:46:04.003 回答