以下是我的DTO。如何从DTO筛选JSON中的属性
public class CustomerTO
{
public int Id { get; set;}
public string Name { get; set;}
//& so on
}
但是,当我从我的操作中返回JSON字符串时,我只想要将少量属性发送到客户端。
的json应该像
{
"id": 1,
"name": "Ram"
}
我的行动。
public string GetCustomers()
{
List<CustomerTO> customers = dal.Get();
var strJson = JsonConvert.SerializeObject(customers);
return strJson;
}
上述动作返回字符串: -
[
{
"id":1,
"name":"Ram",
"age":27,
"Country":"India"
},
{
"id":2,
"name":"Shyam",
"age":27,
"Country":"India"
}
]
我如何在JSON从DTO过滤性能?
的可能的复制【如何排除JSON序列化属性(http://stackoverflow.com/questions/10169648/如何排除属性从JSON序列化) –
@NateBarbettini,我检查使用[ScriptIgnore]中提到的链接,但它没有过滤 –
使用'[JsonIgnore]':http://stackoverflow.com/a/ 25566387/3191599(不知道为什么这不是旧问题的答案) –