wcf deserialize enum as string

此生再无相见时 提交于 2019-12-01 14:58:42

This might be a silly question.

What happens if you do

[DataMember( Name = "foo" )]
private string foo { get; private set; }

public Foo Foo 
{ 
  get 
  {
    return Foo.Parse(foo);
  }
}

?

I know this is an old post, but I think it worth mentioning.

I received a similar error where the deserialization of the json string failed, seeming to deserialize to the wrong types.

The fix for me was to simply URL encode the json string before sending it to the server. A simple but easy mistake to make.

HttpUtility.UrlEncode(JSONInstruction) /*remember to encode the string*/

Er..? Aren't enums integer? The exception is valid. I dunno if this helps: http://msdn.microsoft.com/en-us/library/aa347875.aspx

This perhaps is happening because the setter is private and the reported error is misleading. The Foo is the first property to be deserialized and since no public setter is available it throws an exception.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!