2016-09-01 3 views
1

속성 중 하나가 "easting" 인 json 데이터를 다운로드하려고합니다. json으로 데이터 세트의 대부분을 위해, "easting"는 정수이지만, 아래 그림과 같이 "easting"는 정수의 목록 인 경우 소수이 있습니다deserialization 중 다양한 데이터 형식의 입력을 처리하는 방법은 무엇입니까?

"easting" : 357570 , 
... 
"easting" : [ 434939, 434942 ] , 

내 원래의 코드가 int 경우로 "easting"을 예상했던

public class Item 
{ 
    public int easting { get; set; } 
} 

는 그러나, 나는 점점 오류가 나는 유형 int []에 유형 int 변환 할 수 없습니다 자꾸 다음과 같이 동급 선언했다. eastingint [] 유형이되도록 클래스 정의를 조정하면 역방향 오류가 발생합니다. int [] 유형을 int으로 변환 할 수 없습니다.

어떻게 처리해야합니까? deserialization 프로세스 동안 다양한 입력 데이터 유형을 설명 할 수있는 방법이 있습니까?

+0

동적으로 사용할 수 있습니까? 이것 좀 봐 : http://stackoverflow.com/questions/30147272/serialize-a-json-property-that-is-sometimes-an-array – jpgrassi

+1

당신이 Json.net을 사용한다면, 이것은 [ 이 질문] (http://stackoverflow.com/questions/18994685/how-to-handle-both-a-single-item-and-an-array-for-the-same-property-using-json-n) – stuartd

+0

@stuartd 나는 현재 Json.net으로 전환하려고 시도 할지라도 'System.Web.Script.Serialization'에서'JavaScriptSerializer'를 사용하고 있습니다. 감사. – jcusick

답변

0

마지막으로 @stuartd의 제안에 따라 JavaScriptSerializer에서 Json.net으로 역 직렬화 과정을 수행 했으므로 question posted here을 따라 가면서 내 문제를 해결할 수있었습니다.