我正在尝试使用 JSON.NET 反序列化使用数据填充 C# 对象(ImportedProductCodesContainer)。
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 = null)。你能帮我找出问题所在吗?