为什么我的对象(不包含$ id,将它添加到我的Json响应中?)
Json回复:
型号:
public class DivisionWithProductsViewModel
{
public int Id {get;set;}
public string Name {get;set;}
public string Description {get;set;}
public string Thumbnail {get;set;}
public string ThumbnailName {get;set;}
public List<ProductViewModel> ProductList {get;set;}
}
答案 0 :(得分:3)
$id
和$ref
字段用于在JSON中创建对象层次结构。
例如,请参阅此JSON:
{
"people":[
{
"$id":1,
"name":"John",
"children":[
{ "$ref":2 }
]
},
{
"$id":2,
"name":"Jane"
}
]
}
列表children
中的对象与反序列化Jane
时使用的对象完全相同。
如果使用JSON.NET对其进行反序列化,并且更改了Jane
的名称,则会更新“孩子”。简也是因为它是同一个对象引用。