我在一部分中检索具有不同对象类型的JSON。 我将这部分视为动态。强制转换为特定类型
我需要从这个对象中获取数据,所以我创建的类看起来一样像下面的动态数据:
public class SpecificObject1
{
public string Title{get; set;}
public object[] ViewElements{get; set}
public object AnyAttributes{get; set;}
}
这里是我想将其转换为这个特定对象:
var @switch = new Dictionary<Type, Action> {
{ typeof(x),() => jsonObj.Some = jsonObj.Some as SpecificObject1},
{ typeof(y),() => ......}
};
铸造与as
返回null。
编辑: 更改属性,以真实的
动态包括:
AnyAttributes: {object}
Title: "title"
ViewElements: object[0]
'jsonObj.Some'的内容是什么? – HimBromBeere