我正在尝试在我的WCF REST API(ASP.NET v4.5)中使用JSONPatch(KevinDockx版本)。我的运营合同如下: -
1.8.0_xxx
实施如下: -
[OperationContract]
[WebInvoke(UriTemplate = "/{raceId}/participants", Method = "PATCH")]
void UpdateRace(string id, JsonPatchDocument<ParticipantContract[]> participantsContract);
我的数据类似于以下格式,我想在参与者阵列上执行添加,更新删除,移动和交换操作。
public void UpdateRace(string id, JsonPatchDocument<ParticipantContract[]> participantsContract)
{
//Someoperation
}
在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"
}
}
]
}
你能帮助我解决我在这方面的缺失吗?还有其他需要做的事吗?
答案 0 :(得分:0)
我可以看到你的JSON对象无效
import static org.junit.Assert.assertEquals;
import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
public class LocaleTest {
@Before
public void setUp() {
Locale.setDefault(new Locale("lv"));
}
@Test
public void displaysLatvianLocale() {
Locale locale = new Locale("lv");
String expected = "Latviešu";
String actual = locale.getDisplayName();
assertEquals(expected, actual);
}
@Test
public void displaysRussianLocale() {
Locale locale = new Locale("ru");
String expected = "Krievu";
String actual = locale.getDisplayName();
assertEquals(expected, actual);
}
@Test
public void displaysEnglishLocale() {
Locale locale = new Locale("en");
String expected = "Angļu";
String actual = locale.getDisplayName();
assertEquals(expected, actual);
}
}
只检查JSON对象中的任何其他错误并传递有效的JSON将修复错误。