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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:19:47+00:00 2026-05-19T03:19:47+00:00

I am creating a JSON string using James Newton-King’s excellent JSON libary. I create

  • 0

I am creating a JSON string using James Newton-King’s excellent JSON libary.
I create the JSON string using the following line of code:

string userJSON = Newtonsoft.Json.JsonConvert.SerializeObject(existingAdminUser, Newtonsoft.Json.Formatting.None);

The result looks as follows:

"{\"LoginId\":\"0f1b6c88-08ec-416f-b221-7568dc7c242a\",\"Firstname\":\"Charles\",\"Surname\":\"Barber\",\"Fullname\":\"Charles Barber\",\"Email\":\"charles17@test76876.com\",\"Systems\":null,\"IsValid\":false,\"IsValidExcludingSystems\":true,\"ValidationMessage\":\"\"}"

I am then placing this string into my http response using the following line of code:

HttpContext.Current.Response.Write("<input type=\"hidden\" name=\"adminextrainfo\" id=\"adminextrainfo\" value=\"" + userJSON + "\" />");

I am then trying to access/parse the JSON at the client, using:

var userdetails = $.parseJSON(valueOfHiddenField);

The parse attempt fails, and if I try viewing the contents of the field (using an alert) then I only see the very first { char. It seems that the \” character sequence is being treated as a newline by js. How can I encode the hidden field value at the server, or how can I deal with the hidden field value at the client such that it ‘handles’ the \” character sequence?

Thanks very much.

  • 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-19T03:19:48+00:00Added an answer on May 19, 2026 at 3:19 am

    So we have a little escaping / encoding mess here. Your string:

    "{\"LoginId\":\"0f1b6c88-08ec-416f-b221-7568dc7c242a\",\"Firstname\":\"Charles\",\"Surname\":\"Barber\",\"Fullname\":\"Charles Barber\",\"Email\":\"charles17@test76876.com\",\"Systems\":null,\"IsValid\":false,\"IsValidExcludingSystems\":true,\"ValidationMessage\":\"\"}"
    

    isn’t correct unless it is shown in some C# context (e.g. the Visual Studio debugger). All these slashes are only needed if you put this in C# source code. If you assign it to a variable, the variable will store it without the slashes as they are for escaping within the C# code only. They can’t be the root of your problem because they only exist within the Visual Studio Debugger, not within your application.

    However, you can’t just insert the JSON into HTML. It contains several characters (e.g. the double quote at the second position), that have to be escaped because they have a special meaning in HTML.

    So your fix should be:

    HttpContext.Current.Response.Write("<input type=\"hidden\" name=\"adminextrainfo\" id=\"adminextrainfo\" value=\"" + Server.HtmlEncode(userJSON) + "\" />");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below. The line string content = twitterMsg.text; is creating the
I am creating a JSON array exactly as follows (bar using mathrandom). For example
I'm using a simple ajax-enabled WCF service. I'm creating a string of XML on
I am creating a small number of JSON Web Services using JsonResult as part
right now I'm creating an array and using: render :json => @comments This would
I'm creating a simple API that creates typed classes based on JSON data that
I have a string: {0:16970861903381446063,length:1} I tried converting it to an object using the
I have a WCF REST Service which accepts a JSON string One of the
I am creating Menu in the master page using JQuery. i am passing the
I am using RestEasy to marchal entities to JSON. That works okay but somehow

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.