2012-01-13 24 views
0

我有一個需要序列化的對象。
對象序列化:排除序列化到Json字符串的屬性 - DynamicJson

public class Setting 
{ 
    // Exclude from serialization 
    private SettingInfo _key; 
    public SettingInfo Key 
    { 
     get { return _key; } 
     set 
     { 
      _key = value; 
      Key_Id = _key == null ? 0 : _key.Id; 
     } 
    } 

    // Need to be serialized 
    public int Key_Id { get; set; } 
    public string Value { get; set; } 
} 

問:
是否可以排除使用DynamicJsonSettingInfo對象(房產Key)從序列化?

  • 我使用DynamicJson
  • 當前結果:(其中包含序列化Key屬性)
    {"Key":{"Id":20,"Type":"System.String","Name":"ExampleSetting"},
    "Key_Id":20,
    "Value":"New Value"}
  • 請求的結果{"Key_Id":20,"Value":"New Value"}

回答

1

通常你會怎麼做它與道具erty屬性,但在這個庫中沒有屬性。 下面不是很漂亮,但工作的解決方案。

var r = DynamicJson.Serialize(s); 
DynamicJson tt = DynamicJson.Parse(r); 
tt.Delete("Key"); 

r = tt.ToString(); 
+0

這不完全是我想要的,但它的工作原理。謝謝 – hwcverwe 2012-01-16 22:47:37