C# 解析复杂JSON文件时遇到问题
我正在开发一款使用微软Xbox音乐API的应用程序。在执行搜索查询时,我会得到一个JSON字符串,描述可用的相册、艺术家和歌曲,如下所示:C# 解析复杂JSON文件时遇到问题,c#,.net,json,parsing,C#,.net,Json,Parsing,我正在开发一款使用微软Xbox音乐API的应用程序。在执行搜索查询时,我会得到一个JSON字符串,描述可用的相册、艺术家和歌曲,如下所示: { "Artists": { "Items": [{ "Genres": ["Electronic / Dance"], "Subgenres": ["Breakbeat / Electro"], "Id": "music.7AF41000-0200-11DB-89CA-0019B92A3933",
{
"Artists": {
"Items": [{
"Genres": ["Electronic / Dance"],
"Subgenres": ["Breakbeat / Electro"],
"Id": "music.7AF41000-0200-11DB-89CA-0019B92A3933",
"Name": "Hybrid Theory",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.7AF41000-0200-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/artist/hybrid-theory/7af41000-0200-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
},
{
"Genres": ["More"],
"Subgenres": ["Miscellaneous"],
"Id": "music.A1745200-0200-11DB-89CA-0019B92A3933",
"Name": "London Ensemble",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.A1745200-0200-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/artist/london-ensemble/a1745200-0200-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
}],
"TotalItemCount": 2
},
"Albums": {
"Items": [{
"ReleaseDate": "2011-01-26T00:00:00Z",
"Duration": "00:04:26",
"TrackNumber": 15,
"IsExplicit": false,
"Genres": ["Electronic / Dance"],
"Subgenres": ["Dance"],
"Rights": ["Purchase",
"FreeStream",
"Stream"],
"Subtitle": "Original Version",
"Album": {
"Id": "music.6147B006-0100-11DB-89CA-0019B92A3933",
"Name": "Suite Lounge - A Luxury & Unique Collection Of Relaxing Lounge Tunes, Vol. 2",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.6147B006-0100-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/album/area-42/suite-lounge-a-luxury-unique-collection-of-relaxing-loun/6147b006-0100-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
},
"Artists": [{
"Role": "Main",
"Artist": {
"Id": "music.98D90600-0200-11DB-89CA-0019B92A3933",
"Name": "Area 42",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.98D90600-0200-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/artist/area-42/98d90600-0200-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
}
}],
"Id": "music.EF46B006-0100-11DB-89CA-0019B92A3933",
"Name": "Hybrid Theory",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.EF46B006-0100-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/track/area-42/suite-lounge-a-luxury-unique-collection-of-relaxing-loun/hybrid-theory/ef46b006-0100-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
},
{
"ReleaseDate": "2014-02-19T00:00:00Z",
"Duration": "00:05:30",
"TrackNumber": 2,
"IsExplicit": false,
"Genres": ["Electronic / Dance"],
"Subgenres": ["Dance"],
"Rights": ["Purchase",
"FreeStream",
"Stream"],
"Album": {
"Id": "music.99C82B08-0100-11DB-89CA-0019B92A3933",
"Name": "The Dark",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.99C82B08-0100-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/album/hybrid-theory/the-dark/99c82b08-0100-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
},
"Artists": [{
"Role": "Main",
"Artist": {
"Id": "music.7AF41000-0200-11DB-89CA-0019B92A3933",
"Name": "Hybrid Theory",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.7AF41000-0200-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/artist/hybrid-theory/7af41000-0200-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
}
}],
"Id": "music.9BC82B08-0100-11DB-89CA-0019B92A3933",
"Name": "All Again",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.9BC82B08-0100-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/track/hybrid-theory/the-dark/all-again/9bc82b08-0100-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
}],
"ContinuationToken": "___",
"TotalItemCount": 50
}
class Artist
{
public string Name;
List<string> genres;
bool isExplicit;
}
}
我只有一个相册的类定义,需要从JSON字符串中获取类型为album的列表/数组。然而,我不知道该怎么做。该类如下所示:
{
"Artists": {
"Items": [{
"Genres": ["Electronic / Dance"],
"Subgenres": ["Breakbeat / Electro"],
"Id": "music.7AF41000-0200-11DB-89CA-0019B92A3933",
"Name": "Hybrid Theory",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.7AF41000-0200-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/artist/hybrid-theory/7af41000-0200-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
},
{
"Genres": ["More"],
"Subgenres": ["Miscellaneous"],
"Id": "music.A1745200-0200-11DB-89CA-0019B92A3933",
"Name": "London Ensemble",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.A1745200-0200-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/artist/london-ensemble/a1745200-0200-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
}],
"TotalItemCount": 2
},
"Albums": {
"Items": [{
"ReleaseDate": "2011-01-26T00:00:00Z",
"Duration": "00:04:26",
"TrackNumber": 15,
"IsExplicit": false,
"Genres": ["Electronic / Dance"],
"Subgenres": ["Dance"],
"Rights": ["Purchase",
"FreeStream",
"Stream"],
"Subtitle": "Original Version",
"Album": {
"Id": "music.6147B006-0100-11DB-89CA-0019B92A3933",
"Name": "Suite Lounge - A Luxury & Unique Collection Of Relaxing Lounge Tunes, Vol. 2",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.6147B006-0100-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/album/area-42/suite-lounge-a-luxury-unique-collection-of-relaxing-loun/6147b006-0100-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
},
"Artists": [{
"Role": "Main",
"Artist": {
"Id": "music.98D90600-0200-11DB-89CA-0019B92A3933",
"Name": "Area 42",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.98D90600-0200-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/artist/area-42/98d90600-0200-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
}
}],
"Id": "music.EF46B006-0100-11DB-89CA-0019B92A3933",
"Name": "Hybrid Theory",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.EF46B006-0100-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/track/area-42/suite-lounge-a-luxury-unique-collection-of-relaxing-loun/hybrid-theory/ef46b006-0100-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
},
{
"ReleaseDate": "2014-02-19T00:00:00Z",
"Duration": "00:05:30",
"TrackNumber": 2,
"IsExplicit": false,
"Genres": ["Electronic / Dance"],
"Subgenres": ["Dance"],
"Rights": ["Purchase",
"FreeStream",
"Stream"],
"Album": {
"Id": "music.99C82B08-0100-11DB-89CA-0019B92A3933",
"Name": "The Dark",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.99C82B08-0100-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/album/hybrid-theory/the-dark/99c82b08-0100-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
},
"Artists": [{
"Role": "Main",
"Artist": {
"Id": "music.7AF41000-0200-11DB-89CA-0019B92A3933",
"Name": "Hybrid Theory",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.7AF41000-0200-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/artist/hybrid-theory/7af41000-0200-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
}
}],
"Id": "music.9BC82B08-0100-11DB-89CA-0019B92A3933",
"Name": "All Again",
"ImageUrl": "http://musicimage.xboxlive.com/content/music.9BC82B08-0100-11DB-89CA-0019B92A3933/image?locale=en-US",
"Link": "http://music.xbox.com/track/hybrid-theory/the-dark/all-again/9bc82b08-0100-11db-89ca-0019b92a3933?partnerID=___",
"Source": "Catalog"
}],
"ContinuationToken": "___",
"TotalItemCount": 50
}
class Artist
{
public string Name;
List<string> genres;
bool isExplicit;
}
职业艺术家
{
公共字符串名称;
列出流派;
布尔是明确的;
}
我尝试使用,但只能解析值类型而不能解析引用类型。Json.Net应该可以很好地处理它。如果您在创建类时遇到问题,可以使用一个工具,谢谢。抱歉,没有正确阅读文档。