Unable to deserialize array

这一生的挚爱 提交于 2019-12-01 04:02:14

As you can see by default jQuery's Ajax submits it as 'application/x-www-form-urlencoded' which is the default HTML Form Post Content-Type. Unfortunately it doesn't handle nested objects very well and ServiceStack will expect nested objects in the JSV Format.

So for complex types / nested objects you want to tell jQuery to send the request as JSON which you can do by specifying the contentType:application/json parameter e.g:

var data = { "Pid": 0, "Comments": [{ "User": "bbbbbb", "Text": "aaaaaaaa" }]};
$.ajax({
     type: 'POST',
     dataType: "json",
     contentType: "application/json",
     url: 'savecommentsservice',
     data: JSON.stringify(data)
);

I believe you need to add the name of the parameter (request) to your string. Something along the lines of..

$.ajax({
     type: 'POST',
     dataType: "json",
     url: 'savecommentsservice',
     data: {"request": "Pid": 0, "Comments": [{ "User": "bbbbbb", "Text": "aaaaaaaa" }, { "User": "ddddddd", "Text": "ccccccccc"}] },
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!