c# - Deserialize array with ServiceStack -



c# - Deserialize array with ServiceStack -

here's i'm trying post servicestack web service:

$.ajax({ url: 'http://localhost:8092/profiles', type:'post', data: { firstname : "john", lastname : "doe", categories : [ "category 1", "category 2", "category 3" ] }, success: function (response) { $('#response').append('success!'); }, error: function (xhr, ajaxoptions, thrownerror) { alert(xhr.status + ' error: ' + thrownerror); }, datatype: "json" });

and here's destination class:

[route("/profiles", "post")] public class profilerequest { public string firstname{ get; set; } public string lastname{ get; set; } public string[] categories{ get; set; } }

all fields beingness populated except array. can servicestack not handle objects of complexity or missing something?

note: i've seen unable deserialize array suggests using json.stringify() solution still doesn't seem work, in fact makes worse causing no info deserialized.

servicestack can handle this, jquery $.ajax info has json stringified using json.stringify() method , set contenttype application/json otherwise jquery seek posting info application/x-www-form-urlencoded , deserialising fail.

so request should be:

class="lang-js prettyprint-override">$.ajax({ url: 'http://localhost:8092/profiles', type:'post', data: json.stringify({ firstname: "john", lastname: "doe", categories: [ "category 1", "category 2", "category 3" ] }), success: function (response) { $('#response').append('success!'); }, error: function (xhr, ajaxoptions, thrownerror) { alert(xhr.status + ' error: ' + thrownerror); }, contenttype: "application/json", datatype: "json" });

hope helps.

c# javascript jquery json servicestack

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -