1

I want to inject some Json into the Html page returned by the server?

Is there a public function that returns the Json string when Json(someObject) gets called?

Note that I don't want to return Json to the browser in a seperate request. I want to convert an object graph to json and inject it into a script block.

Thanks


Looking at the MVC source code, I found this:

using System.Web.Script.Serialization;
...
            // The JavaScriptSerializer type was marked as obsolete prior to .NET Framework 3.5 SP1
#pragma warning disable 0618
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            response.Write(serializer.Serialize(Data));
#pragma warning restore 0618

Why was it marked obsolete?

1
  • More info regarding how - JavaScriptSerializer Serialize() and rejects GET requests by default stackoverflow.com/a/3991940/516748 Commented Oct 23, 2012 at 2:01

2 Answers 2

1

This should help.

Best way to parse JSON data into a .NET object

Why microsoft made JavaScriptSerializer obsolete prior to .net 3.5 SP1 and again active after that?

I usually use Json.NET though.

Sign up to request clarification or add additional context in comments.

Comments

0

/*I think */it uses an instance of the System.Web.Script.Serialization.JavaScriptSerializer class.

Verified with reflector that it actually does. It's a default one too, no arguments to the constructor and no properties set before it's used.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.