我的前端实现者遇到了一个非常复杂的嵌套 DTO 的奇怪问题。
这是他通过jquery ajax调用传递的json
{"Id":"507e7e5aa6305825c012c606","Name":"test fried chicken","Description":"why you no work","Servings":4,"Author":"unit test","Steps":[{"Instructions":"put chicken in egg","Ingredients":[{"PreparationId":"507e7e34a6305825c012c601","MeasureId":"kilogram","Quantity":2,"MeasureType":"weight"},{"PreparationId":"507e7e36a6305825c012c605","MeasureId":"gram","Quantity":100,"MeasureType":"weight"}]},{"Instructions":"put in flour and cook it up","Ingredients":[{"PreparationId":"507e7e35a6305825c012c603","MeasureId":"gram","Quantity":100,"MeasureType":"weight"}]}]}
这将作为 uri/recipes 的 PUT,然后在请求端转换为 DTO 的默认实例(实际上没有任何信息被反序列化)。
如果我从请求中获取完全相同的 Json 并运行 C# 代码
var d = new ServiceStack.Text.JsonSerializer<RecipeDTO>();
var re = d.DeserializeFromString(theJson);
var client = new JsonServiceClient(uri);
client.Put<RecipeDTOResponse>("/recipes", re);
然后它工作。任何想法为什么会有差异?