我有一个POCO类,它以JSON字符串的形式发送到浏览器中.NET3.5SP1.我只是在使用默认的JSON序列化,我想忽略一些字段.我想在它们上添加一个类似于[System.Xml.Serialization.XmlIgnore]的属性,这样它们就不会被序列化.

推荐答案

I use the ScriptIgnore attribute on my model like so:

public class Item
{
    [ScriptIgnore]
    public Item ParentItem { get; set; }
}

In this particular scenario I was getting a circular reference error from the Json serializer, so I simply ignored it. I was asking a similar question here on SO when I was turned on to the difference between a Model and ViewModel.

Json相关问答推荐

使用JOLT转换来卸载数据

2020-12年草案中的Json列举模式

将PNG图像保存为Python中的JSON文件

使用 jq 从带有转义反斜杠字符的嵌套 JSON 中提取数据

当并非所有子对象都有 Select 器字段时 Select

当 JSON 字段名称有空格时,ABAP 中的 JSON 反序列化

为什么解析的字典相等而腌制的字典不相等?

用powershell条件解析json文件的数组对象

自定义将 struct 解组为切片映射

如何为所有 API 端点全局设置 http.ResponseWriter Content-Type 标头?

如何对使用转换器的 Grails 服务进行单元测试?

.NET 对象最灵活的序列化是什么,但实现起来很简单?

json.dumps 打乱了顺序

IE8 原生 JSON.parse 错误导致堆栈溢出

有必要清理 JSON 吗?

Json.NET 是否缓存类型的序列化信息?

如何转换为 D3 的 JSON 格式?

有什么方法可以判断您安装的 gulp 版本吗?

确保数组中的项目属性在 Json Schema 中是唯一的?

通过url获取json数据并在python中使用(simplejson)