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

  • Home
  • SEARCH
  • 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 7194709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:25:40+00:00 2026-05-28T20:25:40+00:00

My HTTP REQUEST contains a valid JSON string having the double quote in the

  • 0

My HTTP REQUEST contains a valid JSON string having the double quote in the middle of the name “jo\”hn” escaped as seen here (captured by Fiddler Web Debugger)

{"name":"firstName","value":"jo\"hn"},

Note: The request submission process uses the standard jQuery $.ajax(..) call as seen in this article without issue.


Server side issue

My C# ASMX web service method receives the following C# string value that has the middle double quote unescaped (i.e. backslash has been removed). This cannot be deserialized without causing the error seen below.

This is where the disjoint in the process happens, before I receive the value into my web method. It’s as if ASP.NET is processing the string internally by unescaping it and putting it back together with no escapes, altering the original value instead of providing it verbatim to the web method parameter.

C# String is:

{"name":"firstName","value":"jo"hn"},

The ASMX Web method is roughly:

using System.Web.Script.Serialization;
using System.Web.Script.Services;

[WebMethod]
[ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public string saveData(string values)
{
    JavaScriptSerializer json = new JavaScriptSerializer();
    request = json.Deserialize<List<NameValuePair>>(values.ToString());
                // ^^^ KABOOM! 

The exception message understandably is:

{“Invalid object passed in, ‘:’ or ‘}’ expected. (423):
[{\”name\”:\”plc$lt$zoneHeaderTopNav$searchBoxTopNav$txtWord\”,\”value\”:\”\”},{\”name\”:\”salutation\”,\”value\”:\”Mr\”},{\”name\”:\”firstName\”,\”value\”:\”joh\”n\”},{\”name\”:\”lastName\”,\”value\”:\”smith\”},{\”name\”:\”initial\”,\”value\”:\”d\”}]”}

How do I best go about solving this problem without changing away from classic ASMX web services?

I might consider a front handler that cleans up the incoming request, or maybe running a string cleanup at the beginning of the web service method. Maybe a different JSON library.

However I wonder if there is an easy answer: tweak configuration, use an Attribute, a setting or overload method that might solve the problem?

I’ve done quite a bit of poking around the Internet but most articles cover returning JSON data from the server to the client and dealing with issues in that area.


Addendum Note: full client-side call details requested by Darin Dimitrov

UPDATE: Darin’s Answer posted here inline, for easy reference

function SaveDraft() {

    $.checklist.checkvalid();
    var formObj = $(':input:not([type=hidden])').serializeArray();

    var request = JSON.stringify(formObj);
    request = request.replace(/'/g, "");

    $.ajax({
        url: "/Service.asmx/saveData",
        type: "POST",

        // *** Original erroneous line: uses string concat - commented out
        // data: "{'values':'" + request + "'}",

        // *** CORRECTED LINE: provides an object instead of a string and calls JSON stringify.
        data: JSON.stringify({ values: request }), 

        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: SaveDraftSuccess,
        error: SaveDraftFail
    });
}

Note: This is the embodiment of the call that produces the valid JSON fragment shown at the top of the question.

  • 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-28T20:25:41+00:00Added an answer on May 28, 2026 at 8:25 pm

    Why are you doing this horrible manual JSON deserialization in your web service? Let me suggest you a far better approach.

    Start by defining a model:

    public class Person
    {
        public string Name { get; set; }
        public string Value { get; set; }
    }
    

    then a web method:

    [WebMethod]
    [ScriptMethod]
    public string SaveData(Person person)
    {
        ...
    }
    

    and then you could invoke it from javascript. For example using jQuery:

    $.ajax({
        url: 'foo.asmx/SaveData',
        type: 'POST',
        contentType: 'application/json',
        data: JSON.stringify({
            person: {
                name: 'firstName',
                value: ' jo\"h\'n'
            }
        }),
        success: function(result) {
            alert(result.d);
        }
    });
    

    No kabooms anymore.

    The JSON.stringify method shown here is built-in modern browsers but if you need to support legacy browsers you could include the json2.js script to your page.


    UPDATE:

    Now that you have shown your code it seems that you are not encoding your request. Try like this:

    var formObj = $(':input:not([type=hidden])').serializeArray();
    var request = JSON.stringify(formObj);
    $.ajax({
        url: "/Service.asmx/saveData",
        type: "POST",
        data: JSON.stringify({ values: request }),
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        success: SaveDraftSuccess,
        error: SaveDraftFail
    });
    

    Things to notice: you don’t need regeular expressions to remove single quotes and you should use JSON.stringify to properly encode your request values.

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

Sidebar

Related Questions

I have a query string passed in through an HTTP request that has this
here's i mode code! when i send http request from firefox it work fine!
I'm using .NET MVC 2 If an incoming request contains the URL: http://something.com/1234 where
How do I send a get http request which contains sql query with LIKE
Why does an HTTP PUT request have to contain a representation of a 'whole'
consider the following http request: GET /defects?group-by=priority I would like the returned collection(feed) of
I have long HTTP request ( generating large Excel file - about 60K records
I am making an http request which ends up taking more than 8 mins.
How to send an http request with either post/get method using javascript as an
I need loging all HTTP request (from any application). I have Delphi 7.0. Anybody

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.