Json Deserialization

Topics: Web Api
May 11, 2011 at 2:49 AM
Edited May 11, 2011 at 2:51 AM

I've got the following class:

 

public class EmailAdd {

  public string Email { get; set; }
  public bool Force { get; set; }

}

My method looks like:

[WebInvoke(UriTemplate = "", Method = "POST")]
public HttpResponseMessage<EmailAddResponse> AddEmail(HttpRequestMessage<EmailAdd> email) {
.....
}

 

How come the following Json post fails:

{Email:"brianl@emaildirect.com", Force: true}

 

But this works:

{"Email":"brianl@emaildirect.com", "Force": true}

 

Do I really need to tell all the users to surround all property names with quotes? Why won't the JsonMediaTypeFormatter handle this correctly?

May 11, 2011 at 4:06 AM

According to http://JSONLint.com, the first example you gave is not valid Javascript.  However, the second is.  

May 11, 2011 at 4:10 PM

Touché