Note that there are some explanatory texts on larger screens.

plurals
  1. POJsonValue returned by MVC Web Api is empty in client side
    primarykey
    data
    text
    <p>I'm using MVC web Api for RESTful purpose. My controller methods return serialized Json object in string format. I've got some simple method like this:</p> <pre><code>public string Put(Folder folder) { var folder1 = new Folder{Id="1", IsShared=true,Name= folder.Name}; var jsSerializer = new JavaScriptSerializer(); return jsSerializer.Serialize(folder1); } </code></pre> <p>I call Get, Put, Delete and Post methods in QUnit test like this and it works fine:</p> <pre><code>ajax: { getData: function (url, data) { return processRequest(url, data, "GET"); }, postData: function (url, data) { return processRequest(url, JSON.stringify(data),"POST"); }, updateData: function (url, data) { return processRequest(url, JSON.stringify(data),"UPDATE"); }, deleteData: function (url, data) { return processRequest(url, JSON.stringify(data),"DELETE"); }, processRequest: function (url, data, type) { return $.ajax({ type: type, dataType: "json", contentType: "application/json;charset=utf-8", url: url, data: data, processData: true }); } }, </code></pre> <p>I need to change return value from string to actual Json object because my client doesn't want serialized Json anymore. They need actual Json object. So I changed the method return type to JsonValue and parse the serialized Json object using JsonValue.Parse() method. When I trace my codes in server side, JsonValue object has proper values in its properties and looks fine but the returned JsonValue in client side has empty properties. here is changed method:</p> <pre><code>public JsonValue Put(Folder folder) { var folder1 = new Folder{Id="1", IsShared=true,Name= folder.Name}; var jsSerializer = new JavaScriptSerializer(); return JsonValue.Parse(jsSerializer.Serialize(folder1)); } </code></pre> <p>here is test result:</p> <pre><code>Expected: { "Id": "1", "IsShared": true, "Name": "abc" } Actual: { "Id": [], "IsShared": [], "Name": [] } </code></pre> <p>I appreciate any idea.</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.
 

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