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 ?     
}

2 Answers 2

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.

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

Comments

2

What do you mean by "empty string" ?

The JSON representation of an empty string is "", not an empty string. An empty string actually means "nothing", so null

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.