我试图获取歌曲信息,这是从JSON文件中解析的。
这是我的Music
类,用于解析数据并将数据写入List<TrackData>
public class Music
{
[DataContract]
public class TrackData
{
[DataMember]
public int id { get; set; }
[DataMember]
public int owner_id { get; set; }
[DataMember]
public string artist { get; set; }
[DataMember]
public string title { get; set; }
[DataMember]
public int duration { get; set; }
[DataMember]
public string url { get; set; }
[DataMember]
public int genre_id { get; set; }
[DataMember]
public int? lyrics_id { get; set; }
[DataMember]
public int? album_id { get; set; }
}
[DataContract]
public class JsonData
{
[DataMember]
public int count { get; set; }
[DataMember]
public List<TrackData> items { get; set; }
}
[DataContract]
public class JsonResponse
{
[DataMember]
public JsonData response { get; set; }
}
public static JsonResponse Deserialize(String Json)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(JsonResponse));
MemoryStream stream1 = new MemoryStream(Encoding.UTF8.GetBytes(Json));
JsonResponse result = (JsonResponse)ser.ReadObject(stream1);
return result;
}
}
到目前为止,我能够通过以下方式获取数据:
Music.JsonResponse Response = Music.Deserialize(await GetAudio()); // This is working like a charm, so no need to rewrite this function
Music.JsonData Data = Response.response; // Assigning Parsed JSON to the class and later to TrackData
Music.TrackData Track = Data.items.FirstOrDefault(); // I need data for all of the tracks, not only for the first one
MessageDialog ResultDialog = new MessageDialog(Track.artist); // So im getting only first value of the List
ResultDialog.ShowAsync();
我想将此列表分配给普通列表,但无法将其分配给标题,而不是仅仅获取AsemblyName.Namespace.Music+TrackData
100条记录(在我的本地库中)
所以我想将所有值都放到一个字符串中(每首歌都包含一个字符串中的所有数据),并且能够获取所有歌曲的数据,而不仅仅是第一个
尝试了许多事情,但似乎没有任何帮助。对不起这个问题,也许它相对简单,但我是C#的新手
提前致谢。