2017-10-03 13 views
0

내 WCF REST API (ASP.NET v4.5)에서 JSONPatch (KevinDockx 버전)를 사용하려고합니다. 내 작업 계약은 다음과 같습니다 : -잘못된 페이로드 오류가 발생하는 JSONPatch WCF REST API

[OperationContract] 
[WebInvoke(UriTemplate = "/{raceId}/participants", Method = "PATCH")] 
void UpdateRace(string id, JsonPatchDocument<ParticipantContract[]> participantsContract); 

그리고 구현은 다음과 같습니다 : -

public void UpdateRace(string id, JsonPatchDocument<ParticipantContract[]> participantsContract) 
{ 
    //Someoperation 
} 

내 데이터는 I 업데이트, 추가 수행 삭제, 이동 및 스왑 작업 할 아래 형식과 같다 참가자 배열. 나는 오류가 아래에 무엇입니까 JSON의 직렬화에

{ 
    "raceId" : 1 
    "participants": [ 
     { 
      "id": "abc", 
      "car": "Mercedes", 
      "model": "F1 W08 EQ Power", 
      "teamname": "Mercedes-AMG Petronas Motorsport", 
      "driver": { 
       "id": "111", 
       "firstname": "Lewis", 
       "lastname": "Hamilton", 
       "age": "29" 
      }, 
      "codriver": { 
       "id": "222", 
       "firstname": "Valtteri", 
       "lastname": "Bottas", 
       "age": "32" 
      } 
     }, 
     { 
      "id": "def", 
      "car": "Ferrari", 
      "model": "SF70H", 
      "teamname": "Scuderia Ferrari", 
      "borrower": { 
       "id": "333", 
       "firstname": "Sebastian", 
       "lastname": "Vettel", 
       "age": "30" 
      }, 
      "coborrower": { 
       "id": "444", 
       "firstname": "Kimi", 
       "lastname": "Räikkönen", 
       "age": "37" 
      } 
     } 
    ] 
} 

: -

{ 
    "summary": "Bad Request", 
    "details": "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'ParticipantContract' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath '', line 1, position 1." 
} 

당신은 내가이 누락하고있는 무슨 나를 도와 드릴까요? 추가로 수행해야 할 것이 있습니까? 나는 당신의 JSON 개체를 볼 수있는

답변

0

{ 
     "raceId" : 1 // you missed comma here 
     "participants": [ 
     { 

은 그냥 JSON 객체의 다른 실수를 확인하고 유효한 JSON 오류가 해결됩니다 통과 유효하지 않습니다.