每次艺术家都有"&"他们名字上的符号出现了我的标签" R3HAB VINAI"而不是" R3HAB&威奈"我想得到整个字符串,因为它对最终用户更有用。奇怪的是"&"符号出现在曲目名称就好了。也许有人可以告诉我我做错了什么。
last.fm来自user.getRecentTracks的JSON API数据
{
recenttracks:{
track:[
{
artist:{
#text:"R3HAB & VINAI",
mbid:"eb0fbe2c-6eb7-40bc-900b-3e056c158125"
},
name:"HOW WE PARTY",
streamable:"0",
mbid:"b410da12-f308-4e2f-af88-19c69312e450",
album:{
#text:"",
mbid:""
},
url:"https://www.last.fm/music/R3HAB+&+VINAI/_/HOW+WE+PARTY",
image:[
{
#text:"",
size:"small"
},
{
#text:"",
size:"medium"
},
{
#text:"",
size:"large"
},
{
#text:"",
size:"extralarge"
}
],
@attr:{
nowplaying:"true"
}
},
{
artist:{
#text:"Alan Walker",
mbid:""
},
name:"Sing me to Sleep",
streamable:"0",
mbid:"",
album:{
#text:"",
mbid:""
},
url:"https://www.last.fm/music/Alan+Walker/_/Sing+me+to+Sleep",
image:[
{
#text:"",
size:"small"
},
{
#text:"",
size:"medium"
},
{
#text:"",
size:"large"
},
{
#text:"",
size:"extralarge"
}
],
date:{
uts:"1501613749",
#text:"01 Aug 2017, 18:55"
}
}
],
@attr:{
user:"SomeName",
page:"1",
perPage:"1",
totalPages:"8676",
total:"8676"
}
}
}
C#类列表
public class Rootobject
{
public Recenttracks recenttracks { get; set; }
}
public class Recenttracks
{
public Track[] track { get; set; }
public Attr attr { get; set; }
}
public class Attr
{
public string user { get; set; }
public string page { get; set; }
public string perPage { get; set; }
public string totalPages { get; set; }
public string total { get; set; }
}
public class Track
{
public Artist artist { get; set; }
public string name { get; set; }
public string streamable { get; set; }
public string mbid { get; set; }
public Album album { get; set; }
public string url { get; set; }
public Image[] image { get; set; }
public Attr1 attr { get; set; }
public Date date { get; set; }
}
public class Artist
{
[JsonProperty("#text")]
public string text { get; set; }
public string mbid { get; set; }
}
public class Album
{
public string text { get; set; }
public string mbid { get; set; }
}
public class Attr1
{
public string nowplaying { get; set; }
}
public class Date
{
public string uts { get; set; }
public string text { get; set; }
}
public class Image
{
public string text { get; set; }
public string size { get; set; }
}
答案 0 :(得分:4)
你很可能需要逃脱&符号。
UseMnemonic
属性切换到标签上的false
来技术上执行此操作,而无需转义&符号。TextFormatFlag
进行,如果您不想逃避它&&
HttpUtility.HtmlEncode()
或将所有&
切换为&
WebUtility.HtmlEncode()
1>来依赖System.Web
答案 1 :(得分:2)
默认情况下,&符号(&)被解释为"为下面的字符加下划线并使其成为键盘快捷键。" (当然,不显示&符号。)所以,你有两个选择:
将标签的UseMnemonic
属性设置为false
,告诉它不要尝试解释任何&符号,或
用两个&符号替换每个&符号,这是一个特殊的序列,这意味着"单独留下这个&符号"。 (当然只显示一个&符号。)
答案 2 :(得分:0)
当显示到WinForm时,您需要转义&符号以显示它。您可以通过用&&
替换所有匹配项来完成此操作。
在设置艺术家之前,请在包含它的字符串上执行此操作:
artist = artist.Replace("&", "&&");