T_T*_*T_T 7 json.net asp.net-web-api
我使用Metadata和JsonIgnore来删除序列化中的特殊字段.
[Authorize(Roles = "admin")]
public class UserController : ApiController
{
public IEnumerable<user> Get()
{
using (var mydb = new ModelContainer())
{
return mydb.userSet.ToList();
}
}
}
[MetadataType(typeof(user_Metadata))]
public partial class user
{
private class user_Metadata
{
[JsonIgnore]
public virtual password { get; set; }
public virtual adminFile { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
如何动态控制应该序列化哪个字段.对于某些事情
public partial class user
{
private class user_Metadata
{
[JsonIgnore]
public virtual password { get; set; }
[Roes == admin?JsonIgnore:JsonNotIgnore] //some thing like this
public virtual adminFile { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5655 次 |
| 最近记录: |