我正在尝试遍历JSON数组以获取size:large
的网址。 #text
属性让我感到困惑,因为我无法将其包含在我的点符号中。我可以用这个来size=large
:
json.track.album.image[2].size
但json.track.album.image[2].#text
无效。
以下是JSON数据的片段:
{"track":{"id":"1019817","name":"Believe","mbid":"13194c93-89c6-4ab4-aaf2- 15db5d73b74e","url":"http:\/\/www.last.fm\/music\/Cher\/_\/Believe","duration":"222000","streamable":{"#text":"1","fulltrack":"0"},"listeners":"287271","playcount":"1206650","artist":{"name":"Cher","mbid":"bfcc6d75-a6a5-4bc6-8282-47aec8531818","url":"http:\/\/www.last.fm\/music\/Cher"},"album":{"artist":"Cher","title":"The Very Best of Cher","mbid":"5df00011-6e57-4837-99ae-61f398481db5","url":"http:\/\/www.last.fm\/music\/Cher\/The+Very+Best+of+Cher","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/71997588.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/71997588.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/174s\/71997588.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/71997588.png","size":"extralarge"}],
答案 0 :(得分:1)
由于领先#
,您必须使用[]
语法:
json.track.album.image[2]['#text']
这允许您将键指定为字符串,因此允许使用特殊字符。