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
    0
    votes
    1 answer

    Ignore DateTime prop from being serialized (not working)

    i have tried the solution proposed in this solution i have a class public class MyClass { [IgnoreDataMember] public DateTime? Date { get; set; } } when the JavaScriptSerializer serializes the result it changes the date time for example if…
    John x
    • 4,031
    • 8
    • 42
    • 67
    0
    votes
    1 answer

    Retrieve all values of a dynamically generated html table

    I have a html table displayed in a showmodal dialog window, the html-body has several divs, each div having several tables, tr and td within them. The user will update entries within the input tag so i need to capture the change. One such div looks…
    Haran Murthy
    • 341
    • 2
    • 10
    • 30
    0
    votes
    2 answers

    Getting input field type when using jQuery's .serialize()

    Is it possible when using jQuery's $.serialize() or $.serializeArray() to get the types of input fields (their attributes) that are being serialized? Obviously it sends the input names in the headers, but I'm wondering if I could grab like:…
    bob_cobb
    • 2,229
    • 11
    • 49
    • 109
    0
    votes
    2 answers

    JavaScriptSerializer, Parsing Json from HttpRequest, put pars into a table to be displayed

    I made a call to a web server called Sample ApI. I want to be able to parse that data that's in json or xml, either would be nice and display it in a table format. This is what I have so far. All I want is to be able to parse the data that's in…
    Yusuf
    • 611
    • 4
    • 9
    • 21
    0
    votes
    2 answers

    deserialize json

    I am trying to call a web-service from an aspx page. The web-service returns json. I need to deserialize the json objects. I tried to extract the string, it is of the form : "{ \" d \" : [ { \" _type \" : \" Myclass:#serviceName \", ....other…
    0
    votes
    3 answers

    How to convert a json string?

    Can't seem to get this working. I have this json string and I want to convert it to a C# object: {"name":"mousePos","args":[{"mouseDet":{"rid":"1","posx":1277,"posy":275}}]} I've been trying JavaScriptSerializer but I'm having no luck. I'm unsure…
    Joey Morani
    • 25,431
    • 32
    • 84
    • 131
    0
    votes
    1 answer

    Can't deserialzie an object that has a sublist

    So I have this object: public class JournalItem { public string Description { get; set; } public bool IsShared { get; set; } public bool IsDeleted { get; set; } public bool IsGroup { get; set; } public Guid Id { get; set; } …
    Colin DeClue
    • 2,194
    • 3
    • 26
    • 47
    0
    votes
    2 answers

    $.getJSON doesn't read my .aspx return

    So I searched through most of the getJSON questions and am still unable to find a solution to my problem. My main problem is this: I have a .js file that makes a $.getJSON call to an .aspx page. The .aspx page returns a json object. I've tested the…
    BrianS
    • 1
    • 1
    0
    votes
    1 answer

    twitter json - unable to convert to jobject or jarray using json.net / javascriptserializer

    I am been stuck on this for 3 days now...I have been accessing the twitter api to pull a user_timeline for a list of users and the json that comes back is impossible to work with. I tried to deserialize it using javascriptserializer and get an…
    vbNewbie
    • 3,291
    • 15
    • 71
    • 155
    0
    votes
    1 answer

    Deserialization of a json string returns null values

    This is the JSON string - "{\"body\":[\"VAL1\",\"VAL2\"],\"head\":{\"result\":true,\"time\":3.859}}" These are my classes - [Serializable] public class ResponseHead { public bool result {get; set;} public float…
    neuDev33
    • 1,573
    • 7
    • 41
    • 54
    0
    votes
    1 answer

    serialize datatable to JSON issue vb.net

    Ok, I'm trying to serialize a data table in vb.net: Dim dt As New System.Data.DataTable and for the serializer: Dim js As JavaScriptSerializer = New JavaScriptSerializer() dim jsonString as string jsonString=js.serialize(dt) when it serialize the…
    Eldon Lesley
    • 915
    • 6
    • 19
    • 38
    -1
    votes
    1 answer

    Deserialize json string using JavaScriptSerializer

    I am working on deserialize json string using JavaScriptSerializer in C#, and trying to parse the json string and map it to the appropriate columns in the sql server table for inserting data. I have the sample json string as below. JSON { …
    paone
    • 828
    • 8
    • 18
    -1
    votes
    2 answers

    POST JSON string from Form in VB.NET

    Here is my situation: I have a form that is collecting a list of items in a textarea as a JSON Object. The form textarea looks like this: