我们将过滤器查询作为 JSON 字符串存储在数据库中
但是,当尝试将其转换为 IFilterRule 时,它会引发错误
我检索查询并尝试将其反序列化为 IFilterRule
var includeQuery = JsonConvert.DeserializeObject<IFilterRule>(x.IncludeQuery);
var data = _usedService.Find(id).BuildQuery(includeQuery).ToList();
但它抛出了这个错误,关于我做错了什么的任何想法?
Could not cast or convert from System.String to Castle.DynamicLinqQueryBuilder.IFilterRule.
[ArgumentException: Could not cast or convert from System.String to Castle.DynamicLinqQueryBuilder.IFilterRule.]
Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType) +244
Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType) +123
Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType) +486
[JsonSerializationException: Error converting value "{
condition: "AND",
rules: [
{
id: "Status",
field: "Status",
type: "integer",
input: "checkbox",
operator: "in",
value: [
2,
3
]
}
],
"valid": true
}" to type 'Castle.DynamicLinqQueryBuilder.IFilterRule'. Path '', line 1, position 335.]