Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:15:47+00:00 2026-06-12T11:15:47+00:00

I’m using MVC web Api for RESTful purpose. My controller methods return serialized Json

  • 0

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:

public string Put(Folder folder)
{
   var folder1 = new Folder{Id="1", IsShared=true,Name= folder.Name};
   var jsSerializer = new JavaScriptSerializer();
   return jsSerializer.Serialize(folder1);
}

I call Get, Put, Delete and Post methods in QUnit test like this and it works fine:

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
            });
        }
    },

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:

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));
}

here is test result:

Expected:   
{
  "Id": "1",
  "IsShared": true,
  "Name": "abc"
}

Actual:
{
  "Id": [],
  "IsShared": [],
  "Name": []
}

I appreciate any idea.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:15:48+00:00Added an answer on June 12, 2026 at 11:15 am

    What I did to fix is adding Newtonsoft.Json.dll to my project and using Newtonsoft.Json.Linq.JToken instead of using System.Json.JsonValue. here is my method implementation:

      public Newtonsoft.Json.Linq.JToken Put(Folder folder)
      {
         var folder1 = new Folder{Id="1", IsShared=true,Name = folder.Name};
         var jsSerializer = new JavaScriptSerializer();
         return Newtonsoft.Json.Linq.JObject.Parse(jsSerializer.Serialize(folder1));
      }
    

    and if you have an array of JSON, you need to parse like this:

    public Newtonsoft.Json.Linq.JToken Put(IList<Folder> folders)
          {
             var folder1 = new Folder{Id="1", IsShared=true,Name = folder.Name};
             var jsSerializer = new JavaScriptSerializer();
             return Newtonsoft.Json.Linq.JArray.Parse(jsSerializer.Serialize(folders));
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
i got an object with contents of html markup in it, for example: string
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.