Alex Rivera | Logout

Why JSON empty string deserializes to null at the server side?

Asked 2010-10-01T12:26:23.460
10

I'm sending empty string through $.post and it deserializes to null. How to differentiate if the string was empty or null at the client side ?

Regards

UPDATE What I'm actually doing is:

$.post("Controller/Action", $.param({Name: ""}, true), null, "json");

at the server:

public Container
{
   public string Name;
}

public void Action(Container container)
{
    bool c = container.Name == null;   // c is true, why ?     
}
Edit
Report

1 Answer

2

A variable with empty value is written in JSON as:

{ "var" : "" }

An empty string is parsed as null as there is no object defined in it.

answered 2010-10-01T12:32:28.013

Your Answer