我有一个有孩子的对象我正在使用JavaScriptSerializer转换为JSON。我正在使用MVC并在视图中使用JavaScriptSerializer:
@Html.Raw(serializer.Serialize(Model.Designs)
我的“设计”对象有子项“DesignDeliveries”,但我需要从JSON字符串中删除这些,所以我尝试使用投影但无法获得我需要的格式
所以我的Designs对象如下:
[{
"BookingDesignId": "e90e9500-0a6a-4d1b-a82a-fa7ca2d7c034",
"DesignName": "Design 600",
"Quantity": 100,
"DesignDeliveries": [{
"BookingId": "3706a896-3b8f-454f-acc8-6540441a3e4a",
"Quantity": 50,
"BookingDesignId": "e90e9500-0a6a-4d1b-a82a-fa7ca2d7c034",
"DepotId": "9"
},
{
"BookingId": "3706a896-3b8f-454f-acc8-6540441a3e4a",
"Quantity": 50,
"BookingDesignId": "e90e9500-0a6a-4d1b-a82a-fa7ca2d7c034",
"DepotId": "18"
}]
}];
但是,我需要:
[{
"BookingDesignId": "e90e9500-0a6a-4d1b-a82a-fa7ca2d7c034",
"DesignName": "Design 600",
"Quantity": 100,
"DesignDeliveries": [];
有谁知道如何实现这个目标?
提前致谢
答案 0 :(得分:1)
克隆 Model.Designs ,清除 DesignDeliveries 的集合,再次序列化克隆的设计。