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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:59:05+00:00 2026-05-16T19:59:05+00:00

I am using DataContractJsonSerializer to serialize an object to json, and then returning to

  • 0

I am using DataContractJsonSerializer to serialize an object to json, and then returning to the client with AJAX. I now need to serialize another object to return along with it. The problem is MSs “d” that wraps around the JSON, that stops me from simply concatenating the strings into a single JSON string.

json = json & """,""SecurityGroups"": 1"

Returns:

{
    "d":"[{
        \"__type\":\"User:#HagarDB\",
        \"ID\":1
    }]\",
    \"SecurityGroup\": 1"
}

Any suggestions would be greatly appreciated. I’d rather not have to make another call to the server to get the other object.

  • 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-16T19:59:05+00:00Added an answer on May 16, 2026 at 7:59 pm

    There are at least two roblems in your code. The first one: you make JSON serialization twice. The second: you can not append JSON string with another data because in the result string will be not more in the JSON format.

    If you use [ScriptMethod(ResponseFormat = ResponseFormat.Json)] attribute for the web method, the object which you give back will be automatically serialized to JSON string. So you should not serialize it manually before.

    If the object which you want serialize is already a string then during the serialization all quoates will ne esacped (" will be replaced to \"). In your case after manual object serialization you received the string [{"__type":"User:#HagarDB", "ID":1}] which is correct JSON string. To verify this you can just paste the string in validator http://www.jsonlint.com/. More about the JSON format you can read on http://www.json.org/.

    If you append the data with another string like "SecurityGroup": 1 (which is not a JSON string, correct will be {"SecurityGroup": 1}) with a comma between the strings you will receive the string

    [{"__type":"User:#HagarDB", "ID":1}], "SecurityGroup": 1
    

    which is also wrong JSON. Correct JSON will be something like

    { "MyArray": [ {"__type": "User:#HagarDB", "ID": 1 } ], "SecurityGroup": 1 }
    

    At the end you return the string as a result of the web methid and receive result in the form {d: result} where all quotas will be escaped:

    {
        "d": "[{\"__type\":\"User:#HagarDB\", \"ID\":1}], \"SecurityGroup\": 1"
    }
    

    This is a JSON string, but it is not what you want.

    The solution of your problem is very simple. You web method can looks like following

    [WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public MyResult MyMethod () {
        List<Users> users = BuildMyInnerInformation();
        return new MyResult { Users: users, SecurityGroup: 1};
    }
    
    public class MyResult {
        public List<Users> Users { get; set; }
        public int SecurityGroup { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.