Json的以下C#代码取自YouTube链接,它有两个相同名称的属性,即author,author2和内部author-name,uri(我改为Uris,因为它是一个关键字)调用url时,它返回所有内容,但不返回author,它显示author为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; }
}
问候,
Siva
您没有将[DataMember]属性分配给author属性。WCF仅序列化DataMembers。
Author2类也缺少[DataContract]属性。
请参阅:http://msdn.microsoft.com/en-us/library/ms733127.aspx