我想用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