我正在序列化我創建的MediaInfo類的對象列表。當這出來,我結束了:JsonConvert SerializeObject不包含[Serializable]類的類屬性名稱
Object:
ClassName: "WVO.Media",
Data: Array():
0:9
1: null
...
5: "A3000"
...
8: "Oakland
... etc...
總之,我得到的類屬性整數鍵控數組而不是屬性名稱。序列化代碼非常簡單。首先,我加載表(表mediaInfos),然後調用:
JsonConvert.SerializeObject(mediaInfos);
我可以RESPONSE.WRITE之類的東西:
Response.Write(mediaInfos[0].MediaTown);
...並得到正確的輸出,但我很困惑,爲什麼這些屬性名稱不包含在JSon輸出中。我錯過了什麼?
編輯:
using System;
using System.Data;
using System.Runtime.Serialization;
using System.Collections.Generic;
using CMS;
using CMS.DataEngine;
using CMS.Helpers;
using WVO;
[assembly: RegisterObjectType(typeof(MediaInfo), MediaInfo.OBJECT_TYPE)]
namespace WVO
{
[Serializable]
public class MediaInfo : AbstractInfo<MediaInfo>
{
#region "Type information"
public const string OBJECT_TYPE = "wvo.media";
public static ObjectTypeInfo TYPEINFO = new ObjectTypeInfo(typeof(MediaInfoProvider), OBJECT_TYPE, "WVO.Media", "MediaID", null, null, null, null, null, null, null, null)
{
ModuleName = "wvo",
TouchCacheDependencies = true,
DependsOn = new List<ObjectDependency>()
{
new ObjectDependency("MediaMarketID", "wvo.mediamarket", ObjectDependencyEnum.NotRequired),
new ObjectDependency("MediaStateID", "cms.state", ObjectDependencyEnum.NotRequired),
new ObjectDependency("MediaTypeID", "wvo.mediatype", ObjectDependencyEnum.NotRequired),
new ObjectDependency("MediaSizeID", "wvo.mediasize", ObjectDependencyEnum.NotRequired),
},
};
#endregion
#region "Properties"
[DatabaseField]
public virtual int MediaID
{
get
{
return ValidationHelper.GetInteger(GetValue("MediaID"), 0);
}
set
{
SetValue("MediaID", value);
}
}
[DatabaseField]
public virtual string MediaPanel
{
get
{
return ValidationHelper.GetString(GetValue("MediaPanel"), String.Empty);
}
set
{
SetValue("MediaPanel", value, String.Empty);
}
}
[DatabaseField]
public virtual string MediaTown
{
get
{
return ValidationHelper.GetString(GetValue("MediaTown"), String.Empty);
}
set
{
SetValue("MediaTown", value, String.Empty);
}
}
... [several other properties similarly formatted] ...
#endregion
#region "Type based properties and methods"
protected override void DeleteObject()
{
MediaInfoProvider.DeleteMediaInfo(this);
}
protected override void SetObject()
{
MediaInfoProvider.SetMediaInfo(this);
}
#endregion
#region "Constructors"
public MediaInfo(SerializationInfo info, StreamingContext context)
: base(info, context, TYPEINFO)
{
}
public MediaInfo()
: base(TYPEINFO)
{
}
public MediaInfo(DataRow dr)
: base(TYPEINFO, dr)
{
}
#endregion
}
}
謝謝!
你能告訴我們什麼是'ObjectTypeInfo'樣子? – vendettamit