我想用JSON.NET反序列化填充數據的C#對象(ImportedProductCodesContainer)。在C#中的JSON.NET反序列化導致空對象
ImportedProductCodesContainer.cs:
using Newtonsoft.Json;
[JsonObject(MemberSerialization.OptOut)]
public class ImportedProductCodesContainer
{
public ImportedProductCodesContainer()
{
}
[JsonProperty]
public ActionType Action { get; set; }
[JsonProperty]
public string ProductListRaw { get; set; }
public enum ActionType {Append=1, Replace};
}
JSON字符串:
{"ImportedProductCodesContainer":{"ProductListRaw":"1 23","Action":"Append"}}
C#代碼:
var serializer = new JsonSerializer();
var importedProductCodesContainer =
JsonConvert.DeserializeObject<ImportedProductCodesContainer>(argument);
的問題是,importedProductCodesContainer保持運行上面的代碼後空( Action = 0,ProductListRaw =空值)。你能幫我弄清楚有什麼問題嗎?
謝謝,這工作! – 2010-06-04 09:20:45