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 5951153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:29:46+00:00 2026-05-22T17:29:46+00:00

I’m working with ASP.NET and jQuery on client side. I’m using Json.NET to serialize

  • 0

I’m working with ASP.NET and jQuery on client side.

I’m using Json.NET to serialize data from the DB on the server side and I’m sending it to the client when an Ajax request arrives.

When I open FireBug, I see the following json:

{"d":"[\r\n  {\r\n    \"CategoryID\": 1,\r\n    \"CategoryName\": \"a\",\r\n    \"Description\": \"123\",\r\n    \"CategoryType\": \"Personal\",\r\n    \"Traits\": [\r\n      {\r\n        \"TraitID\": 1,\r\n        \"TraitName\": \"a\",\r\n        \"Description\": \"aaa\"\r\n      },\r\n      {\r\n        \"TraitID\": 1,\r\n        \"TraitName\": \"a\",\r\n        \"Description\": \"aaa\"\r\n      }\r\n    ]\r\n  },\r\n  {\r\n    \"CategoryID\": 1,\r\n    \"CategoryName\": \"b\",\r\n    \"Description\": \"bla bla\",\r\n    \"CategoryType\": \"Professional\",\r\n    \"Traits\": [\r\n      {\r\n        \"TraitID\": 1,\r\n        \"TraitName\": \"a\",\r\n        \"Description\": \"aaa\"\r\n      },\r\n      {\r\n        \"TraitID\": 1,\r\n        \"TraitName\": \"a\",\r\n        \"Description\": \"aaa\"\r\n      }\r\n    ]\r\n  },\r\n  {\r\n    \"CategoryID\": 1,\r\n    \"CategoryName\": \"c\",\r\n    \"Description\": \"123\",\r\n    \"CategoryType\": \"Personal\",\r\n    \"Traits\": [\r\n      {\r\n        \"TraitID\": 1,\r\n        \"TraitName\": \"a\",\r\n        \"Description\": \"aaa\"\r\n      },\r\n      {\r\n        \"TraitID\": 1,\r\n        \"TraitName\": \"a\",\r\n        \"Description\": \"aaa\"\r\n      }\r\n    ]\r\n  },\r\n  {\r\n    \"CategoryID\": 1,\r\n    \"CategoryName\": \"d\",\r\n    \"Description\": \"bla bla\",\r\n    \"CategoryType\": \"Professional\",\r\n    \"Traits\": [\r\n      {\r\n        \"TraitID\": 1,\r\n        \"TraitName\": \"a\",\r\n        \"Description\": \"aaa\"\r\n      },\r\n      {\r\n        \"TraitID\": 1,\r\n        \"TraitName\": \"a\",\r\n        \"Description\": \"aaa\"\r\n      }\r\n    ]\r\n  }\r\n]"}

My code from server side:

    [WebMethod]
public static string LoadRatingForm()
{
    bll_Trait t1 = new bll_Trait();
    t1.TraitID = 1;
    t1.TraitName = "a";
    t1.Description = "aaa";

    bll_Trait t2 = new bll_Trait();
    t2.TraitID = 1;
    t2.TraitName = "a";
    t2.Description = "aaa";

    bll_Trait t3 = new bll_Trait();
    t3.TraitID = 1;
    t3.TraitName = "a";
    t3.Description = "aaa";

    bll_Trait t4 = new bll_Trait();
    t4.TraitID = 1;
    t4.TraitName = "a";
    t4.Description = "aaa";



    bll_Category c1 = new bll_Category();
    c1.CategoryID = 1;
    c1.CategoryName = "a";
    c1.CategoryType = "Personal";
    c1.Description = "123";
    c1.Traits.Add(t1);
    c1.Traits.Add(t2);

    bll_Category c2 = new bll_Category();
    c2.CategoryID = 1;
    c2.CategoryName = "b";
    c2.CategoryType = "Professional";
    c2.Description = "bla bla";
    c2.Traits.Add(t3);
    c2.Traits.Add(t4);

    bll_Category c3 = new bll_Category();
    c3.CategoryID = 1;
    c3.CategoryName = "c";
    c3.CategoryType = "Personal";
    c3.Description = "123";
    c3.Traits.Add(t1);
    c3.Traits.Add(t2);

    bll_Category c4 = new bll_Category();
    c4.CategoryID = 1;
    c4.CategoryName = "d";
    c4.CategoryType = "Professional";
    c4.Description = "bla bla";
    c4.Traits.Add(t3);
    c4.Traits.Add(t4);

    List<bll_Category> list = new List<bll_Category>();
    list.Add(c1);
    list.Add(c2);
    list.Add(c3);
    list.Add(c4);

    return JsonConvert.SerializeObject(list, Formatting.Indented);
}

My jQuery code:

$.ajax({
            type: "POST",
            url: "MyProfile.aspx/LoadRatingForm",
            data: "{}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                var html;
                var categories = response.d;
                $.each(categories, function (i, category) {
                    // create 
                    //while (category.CategoryType == "Professional") {
                    //
                    //}

                    html += category.CategoryName + " ";
                });
                dialog.append(html);
            },
            error: function () {
                alert("ERROR");
            }
        });

The ‘dialog’ variable is a jQuery UI modal dialog and the $.ajax code is in the dialog’s ‘open’ event handler…

What should I do to make the serialization result in a “correct” json format without any ‘\n’, ‘\r’ and ‘\’ ?

Thanks in advance!

  • 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-05-22T17:29:47+00:00Added an answer on May 22, 2026 at 5:29 pm

    You should not manually JSON serialize that List.

    ASP.NET is already doing it for you automatically when you call it via POST and use a content-type of application/json. So, you’re ending up with a doubly serialized response, and that is why you’ve found that you need to parse it a second time after jQuery has already parsed it once.

    If you use a return type of List and return the list directly, you should be in good shape.

    More info: http://encosia.com/2011/04/13/asp-net-web-services-mistake-manual-json-serialization/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.