我有以下来自YouTube Link的Json的C#代码,其中有两个同名的属性,即作者,author2和内部作者 - 名称,uri(我改为Uris,因为它是关键字)在调用url它返回所有但不是作者,它为作者显示null,帮我修复此
这是我的源代码,
[DataContract]
public class Title
{
[DataMember (Name="$t")]
public string title { get; set; }
}
[DataContract]
public class Name2
{
[DataMember(Name = "$t")]
public string authorname { get; set; }
}
[DataContract]
public class Uri2
{
[DataMember(Name = "$t")]
public string channelurl { get; set; }
}
public class Author2
{
public Name2 name { get; set; }
public Uri2 uri { get; set; }
}
[DataContract]
public class YtChannelId
{
[DataMember (Name="$t")]
public string channelid { get; set; }
}
[DataContract]
public class MediaThumbnail
{
[DataMember(Name = "url")]
public string imgurl { get; set; }
}
[DataContract]
public class MediaGroup
{
[DataMember (Name="media$thumbnail")]
public List<MediaThumbnail> media_thumbnail { get; set; }
}
[DataContract]
public class FeAEntry
{
public List<Author2> author { get; set; }
[DataMember (Name="yt$channelId")]
public YtChannelId channelId { get; set; }
public Title title { get; set; }
[DataMember (Name="media$group")]
public MediaGroup media_group { get; set; }
}
public class FeAFeed
{
public List<FeAEntry> entry { get; set; }
}
public class Name
{
[DataMember (Name="$t")]
public string t { get; set; }
}
public class Uris
{
[DataMember (Name="$t")]
public string t { get; set; }
}
public class Author
{
public Name name { get; set; }
public Uris uri { get; set; }
}
public class FeARootObject
{
public FeAFeed feed { get; set; }
public List<Author> author { get; set; }
}
此致
希瓦
答案 0 :(得分:0)
您没有将[DataMember]属性分配给author属性。只有DataMembers由WCF序列化。
您的Author2类也缺少[DataContract]属性。