Questions tagged [javascriptserializer]

System.Web.Script.Serialization.JavaScriptSerializer is a class which provides JSON serialization and deserialization functionality for applications and web sites targetting the .NET Framework. Use this tag for questions about this specific class only. For more general JavaScript/JSON serialization questions use the [json] and [serialisation] tags.

System.Web.Script.Serialization.JavaScriptSerializer is a class which provides JSON serialization and deserialization functionality for applications and web sites targetting the .NET Framework.

Use this tag for questions about the Microsoft class. For more general JSON serialization questions use both the and tags.

MSDN Remarks

The JavaScriptSerializer class is used internally by the asynchronous communication layer to serialize and deserialize the data that is passed between the browser and the Web server. You cannot access that instance of the serializer. However, this class exposes a public API. Therefore, you can use the class when you want to work with JavaScript Object Notation (JSON) in managed code.

To serialize an object, use the Serialize method. To deserialize a JSON string, use the Deserialize or DeserializeObject methods. To serialize and deserialize types that are not natively supported by JavaScriptSerializer, implement custom converters by using the JavaScriptConverter class. Then register the converters by using the RegisterConverters method.

Example

public abstract class AsSerializable
{
 public string AsJson()
 {
  var serializer = new JavaScriptSerializer();
  return serializer.Serialize(this);
 }
}

public class Foo : AsSerializable
{
 public string Bar { get; set; }
}

string JSON = Foo.AsJson();

MSDN Article

  • JavaScriptSerializer

    JavaScriptSerializer Code

  • Code

    Performance Benchamrks

  • http://james.newtonking.com/archive/2008/10/27/json-net-3-5-beta-1-big-performance-improvements-compact-framework-support-and-more.aspx

  • http://www.servicestack.net/benchmarks/
  • 420 questions
    3
    votes
    2 answers

    How to serialise a javascript object

    When you serialise a form using jQuery.serialize(), the method will serialise the form fields and its values so you can submit to the server. Is there a method/function that would do the same with a javascript object instead of a form?
    WagnerMatosUK
    • 4,309
    • 7
    • 56
    • 95
    3
    votes
    5 answers

    Asmx web service how to return JSON and not XML?

    My service method: [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string getDataFromTrainingMaster() { List results = new DAL().GetDataFromTrainingMaster(); JavaScriptSerializer js = new…
    bapi
    • 1,903
    • 10
    • 34
    • 59
    3
    votes
    1 answer

    JavaScriptSerializer Invalid JSON primitive

    When I use the JavaScriptSerializer in C# I'm getting a "Invalid JSON primitive" exception. I assume the issue is with my json input string but I don't see the problem. JavaScriptSerializer new JavaScjs…
    GoBeavs
    • 499
    • 2
    • 10
    • 25
    3
    votes
    3 answers

    JavaScriptSerializer [ScriptIgnore] not effective on virtual properties?

    I have returning a Json(myObj) action result. The myObj is of type Badge The only two objects that Badge has that could cause a loop from a serializer, are: public class Badge { public Badge() { } public Badge(String Name, String…
    williamsandonz
    • 15,864
    • 23
    • 100
    • 186
    2
    votes
    1 answer

    JSON formatting using JavaScriptSerializer

    Possible Duplicate: How to set formatting with JavaScriptSerializer when JSON serializing? I'm using using System.Web.Script.Serialization to serialize some json. However, by default it makes ugly text without indentation. …
    FlavorScape
    • 13,301
    • 12
    • 75
    • 117
    2
    votes
    2 answers

    JavaScriptSerializer seems to ignore the maxJsonLength configuration

    I was facing the max json length problem so as suggested by various sources on the internet, i increased the default json length in the configuration file like
    John x
    • 4,031
    • 8
    • 42
    • 67
    2
    votes
    2 answers

    Visual Studio Intellisense for JavaScript when generated from JavaScriptSerializer

    What is the correct way for getting JavaScript Intellisense in Visual Studio 2010 when creating a client side object with the JavaScriptSerializer? For example, I have a class named Record with several properties; I'm generating a collection of…
    2
    votes
    2 answers

    Serializing c# class to JSON string with custom column name

    I have this result { "StatusCode": "200", "Description": "Success", "Data": [ { "Language_Key": "btn_select_country", "En_Val": "SELECT COUNTRY", "Ar_Val": "اختر الدولة" }, { …
    Khurram Shaikh
    • 300
    • 2
    • 14
    2
    votes
    1 answer

    Parse JSON on javascript after return JsonConvert.SerializeObject(json) [.NET handler]

    i'm developing an web application in .net platform. i have wrote an Handler code that return a JSON object to Javascript (after i request in AJAX). the Handler code: var wrapper = new { left = left.ToString(), top = top.ToString(), …
    Idoshin
    • 363
    • 2
    • 17
    2
    votes
    0 answers

    Looking for a Java equivalent to JavaScriptSerializer

    I am replacing a VB app that accesses a secure server. My version of the app is written in Java. The app I am replacing uses JavaScriptSerializer to encrypt the login credentials. Is there an equivalent to JavaScriptSerializer in Java?
    2
    votes
    2 answers

    JavaScriptSerializer on JSON containing an array

    There is a similar question with the same title, but the solution is not valid for my problem. I'm trying to serialize the following JSON: {"Id":1, "Questions": [{"Id":"q-1-Q0001","Text":"Volume Too High"}, …
    Paul
    • 402
    • 4
    • 12
    2
    votes
    2 answers

    Can I get JavaScriptSerializer to serialize a LINQ result hierarchically?

    I'm doing this: var data = from a in attributes from i in attributeItems.Where(x=>x.DocClassAttributeFieldId == a.Id ) .DefaultIfEmpty(new DocClassAttributeFieldItem()) select new { …
    Homer
    • 7,594
    • 14
    • 69
    • 109
    2
    votes
    1 answer

    JavaScriptSerializer on JSON containing an array

    I have a string of JSON like this: { "letterstats":[ {"time_taken":636,"mistake_letters":"","the_letter":"L","success":true}, {"time_taken":216,"mistake_letters":"","the_letter":"U","success":true}, …
    JesseBuesking
    • 6,496
    • 4
    • 44
    • 89
    2
    votes
    0 answers

    How to pass embedded JSON using C# web client

    I need to pass embedded JSON file through the API.To achieve that I used following code public static string EvaluateRating(string jsonFile,string vKey, string mobileNo, string nic) { try { object input = new { …
    Sachith Wickramaarachchi
    • 5,546
    • 6
    • 39
    • 68
    2
    votes
    1 answer

    'JavaScriptSerializer' could not be found .net core

    when trying to initialize a variable JavaScriptSerializer javascriptSerializer = new JavaScriptSerializer(); I am getting the following error : 'JavaScriptSerializer' could not be found .net core. i also tried to include the namespace…
    Adithya Sai
    • 1,592
    • 2
    • 19
    • 33