【发布时间】:2016-11-29 21:59:27
【问题描述】:
我需要帮助了解如何使用 JsonConverter.ReadJson 方法将任意数量类型(字符串、布尔值、日期、整数、数组、对象)的值转换为特定的自定义类型。
例如,我有以下;
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
//where reader.Value could be a string, boolean, Date, int, array, object
//and in this example the value of reader.Value is a string
return new MyCustomType(reader.Value);
}
但这会产生错误;
Compilation error (line 115, col 36): Argument 1: cannot convert from 'object' to 'string'
我对 C# 有点陌生,只是需要帮助来完成这项工作。
【问题讨论】:
标签: c# json.net json-deserialization