2015-01-13 1 views
0

Db에서 데이터를 가져 오기 위해 REST 서비스를 사용하고 있습니다. 수업 시간에 "TimeTime"데이터 유형의 "UploadTime"속성을 사용하고 있습니다.휴식 서비스 직렬화의 Timespan과 관련된 문제

ArrayOfUploadUI xmlns="http://schemas.datacontract.org/2004/07/NMS.ApplicationService.HIM.Objects" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> 
<UploadUI> 
    <UID>1</UID> 
    <DateCompleted>2015-01-08T10:46:25.25</DateCompleted> 
    <DateNotified>2015-01-07T10:46:25.25</DateNotified> 
    <DateDictationStartTime i:nil="true" /> 
    <DateDictationEndTime i:nil="true" /> 
    <UploadTime>P1D</UploadTime> 
    <ExistsOnBackend>false</ExistsOnBackend> 
    </UploadUI> 
    </ArrayOfUploadUI> 

: 시간 범위가 날짜 사이의 반응의 차이에 따라 계산되어, 나는 같은 반응을 얻고 마. "response.Content.ReadAsAsync();"

using (HttpResponseMessage response = await _HttpClient(session).GetAsync(apiUrl)) 
      { 
       if (response.IsSuccessStatusCode) 
        result = await response.Content.ReadAsAsync<T>(); 
       else 
        await _HandleInvalidResponseAsync(response); 
      } 

내가에 문제가 점점 오전 : 데이터를 얻을하는 동안 나는 다음과 같은 예외를 얻고있다.

오류입니다 : 내가 봤 내가 WCF가에서 "시간 범위"데이터 유형 serilaizing 것을 알게

Error converting value "P1D" to type 'System.Nullable`1[System.TimeSpan]'. Path '[0].UploadTime', line 1, position 518. 
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType). 

"1 : 0 : 0 : 00"을 "P1D를".

내 문제는 응답 수준에서 역 직렬화하는 방법입니다.

답변

0

원본 수준에서 날짜 서식을 지정 했으므로 문제가 해결되었습니다.

JsonSerializerSettings dateFormatSettings = new JsonSerializerSettings 
      { 
       DateFormatHandling = DateFormatHandling.MicrosoftDateFormat 
      }; 
      string jsonNMSPlatformObject = JsonConvert.SerializeObject(nmsPlatformObject,dateFormatSettings); 
      using (HttpContent httpContent = new StringContent(jsonNMSPlatformObject)) 
      { 
       httpContent.Headers.ContentType = new MediaTypeHeaderValue(JsonMedaType); 
       var request = new HttpRequestMessage(HttpMethod.Delete, apiUrl); 
       request.Content = httpContent; 
       using (HttpResponseMessage response = await _HttpClient(session).SendAsync(request)) 
       { 
        if (response.IsSuccessStatusCode) 
         return; 
        else 
         await _HandleInvalidResponseAsync(response, jsonNMSPlatformObject); 
       } 
      }