Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to deserialize array
    primarykey
    data
    text
    <p>Data sent from client will not get deserialized.</p> <p>Client:</p> <pre><code>$.ajax({ type: 'POST', dataType: "json", url: 'savecommentsservice', data: { "Pid": 0, "Comments": [{ "User": "bbbbbb", "Text": "aaaaaaaa" }, { "User": "ddddddd", "Text": "ccccccccc"}] }, </code></pre> <p>DTO:</p> <pre><code>public class Comment { public string User { get; set; } public string Text { get; set; } } public class SaveCommentsRequest { public int Pid { get; set; } public string SiteId { get; set; } public string Column { get; set; } public List&lt;Comment&gt; Comments { get; set; } } </code></pre> <p>Server:</p> <pre><code>Routes.Add&lt;SaveCommentsRequest&gt;("/savecommentsservice"); ... public object Execute(SaveCommentsRequest request) { // Why is request.Comments null !!! All other params of the request works fine // THe string I'm putting in is generated below - just to make sure its correct request.Comments = new List&lt;Comment&gt;(); request.Comments.Add(new Comment { Text = "aaaaaaaa", User = "bbbbbb" }); request.Comments.Add(new Comment { Text = "ccccccccc", User = "ddddddd" }); var thisIsWhatIPutInto$AjaxCall = JsonSerializer.SerializeToString&lt;SaveCommentsRequest&gt;(request); </code></pre> <p>Any Idea what's wrong? Why is the Comments array not populated. As you can see from the comments I've generated the string with the servicestack json serializer.</p> <p>Maybe I'm missing some obvisous here?</p> <p><strong>EDIT</strong> When looking at fiddler whats beeing transmitted I see this:</p> <pre><code> POST http://localhost:4920/savecommentsservice HTTP/1.1 Host: localhost:4920 User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2 Accept: application/json, text/javascript, */*; q=0.01 Accept-Language: zh,en-us;q=0.7,en;q=0.3 Accept-Encoding: gzip, deflate Connection: keep-alive Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With: XMLHttpRequest Referer: http://localhost:4920/default.cshtml?viewId=3 Content-Length: 227 Cookie: ASP.NET_SessionId=slbw453revfgmwuuxyrim1an Pragma: no-cache Cache-Control: no-cache SiteId=Site1&amp;Pid=0&amp;Column=C6&amp;Comments%5B0%5D%5BUser%5D=bbbbbb&amp;Comments%5B0%5D%5BText%5D=aaaaaaaa&amp;Comments%5B1%5D%5BUser%5D=ddddddd&amp;Comments%5B1%5D%5BText%5D=ccccccccc&amp;Comments%5B2%5D%5BUser%5D=ggggggg&amp;Comments%5B2%5D%5BText%5D= </code></pre> <p>And in firebug:</p> <pre><code> Parametersapplication/x-www-form-urlencoded Column C6 Comments[0][Text] aaaaaaaa Comments[0][User] bbbbbb Comments[1][Text] ccccccccc Comments[1][User] ddddddd Comments[2][Text] Comments[2][User] ggggggg Pid 0 SiteId SiteId0 Source SiteId=SiteId0&amp;Pid=0&amp;Column=C6&amp;Comments%5B0%5D%5BUser%5D=bbbbbb&amp;Comments%5B0%5D%5BText%5D=aaaaaaaa&amp;Comments%5B1%5D%5BUser%5D=ddddddd&amp;Comments%5B1%5D%5BText%5D=ccccccccc&amp;Comments%5B2%5D%5BUser%5D=ggggggg&amp;Comments%5B2%5D%5BText%5D= </code></pre> <p>Regards</p> <p>Larsi</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload