0
我想序列化一個對象樹到JSON字符串。對象樹是複雜的,並且通常序列化沒有問題,例外是來自不同.DLL的對象的一組屬性。無論如何,我可以序列化這些嗎?使用Newtonsoft JsonConvert序列化失敗的特定屬性集
下面是序列化代碼:
var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
var json = JsonConvert.SerializeObject(exe.Value, settings);
File.WriteAllText(Path.Combine(folderCache, exe.Value.AccountId + ".txt"), json);
這裏是類屬性,其中沒有得到序列化的類型:
[DataContract(Namespace = Constants.ServiceManagementNS)]
public class Deployment : IExtensibleDataObject
exe.Value是一個基於的EntityFramework模型對象定義像這樣(結構很深)
[DataContract(IsReference = true)]
[KnownType(typeof(Account))]
public partial class AccountUser: IObjectWithChangeTracker, INotifyPropertyChanged
某處深處我n樹中有一個名爲AzureDeployment的屬性沒有被序列化:
public Deployment AzureDeployment { get; set; }
有什麼建議嗎?
非序列化實體不部署類定義必須標記爲我的其他類[Serializable接口] – aquaraga 2013-04-21 19:53:44
都不是 – Igorek 2013-04-21 20:07:31
你得到任何異常? – MUG4N 2013-04-21 20:07:59