【发布时间】:2016-11-05 11:40:45
【问题描述】:
假设我有以下 2 个 JSON 对象,它们根据传入的参数从同一个 AJAX 调用返回。
第一个返回 child 属性的字符串数组:
{
parent: {
child: [
"item 1",
"item 2",
"item 3",
]
}
}
第二个返回 child 属性的对象数组:
{
parent: {
child: [
{
"attribute1": "Attribute 1",
"attribute2": "Attribute 2",
"attribute3": "Attribute 3"
},
{
"attribute1": "Attribute 1",
"attribute2": "Attribute 2",
"attribute3": "Attribute 3"
},
{
"attribute1": "Attribute 1",
"attribute2": "Attribute 2",
"attribute3": "Attribute 3"
},
]
}
}
是否有可能以某种方式将其中任何一个反序列化为同一模型?也许 child 有 2 个不同的属性(例如 ChildString 和 ChildObject em>) 根据类型相应填充?
我目前正在使用Jil 进行反序列化,但如果需要,我愿意向其他人开放。
谢谢!
【问题讨论】:
标签: c# .net model-view-controller deserialization