다른 객체 유형을 가진 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