【发布时间】:2014-06-01 18:10:56
【问题描述】:
我正在使用允许导出 JSON 的 Draw2D 库,但是当我尝试这样做时,我无法将其导出到 MVC。这不是 Draw2D 的问题,而是我缺乏关于如何让它工作的知识。 我生成如下所示的 JSON
[
{
"type": "DBTable",
"id": "662b1fb8-5eb8-47a5-9f81-e48efb0d31bd",
"x": 80,
"y": 59,
"width": 99,
"height": 107,
"cssClass": "DBTable",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"name": "Default AutoAttendant",
"entities": [
{
"text": "0",
"id": "0c4c5414-1f35-4247-a4b7-38297aa0e5ff"
},
{
"text": "1",
"id": "706e1cb7-a9d1-461d-8230-0bf136c1d850"
}
]
},
{
"type": "NamedUser",
"name": "Scott",
"id": "0d2c71cf-52ee-4c50-a974-ea07003df05e",
"cssClass": "NamedUser",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"x": 220,
"y": 200
},
{
"type": "NamedUser",
"name": "Nancy",
"id": "601b0ad9-a0e9-4604-8861-38694a43e0a8",
"cssClass": "NamedUser",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"x": 220,
"y": 200
}
]
我的控制器目前非常基本,可以清除所有潜在的副作用问题。
public ActionResult Draw2dRetrieveJSON(AllJson AllJsontxt)
{
我的班级是这样的
public class AllJson
{
public IEnumerable<HostedVoiceUserJson> HostedVoiceUserJson { get; set; }
//public IEnumerable<HostedVoiceHuntGroupJson> HostedVoiceHuntGroupJson { get; set; }
//public IEnumerable<HostedVoiceAAJson> HostedVoiceAAJson { get; set; }
//public IEnumerable<HostedVoiceConnectionJSON> HostedVoiceConnectionJSON { get; set; }
}
我关注了这篇文章,它让我自己发布“NamedUser”对象并手动更改 JSON 字符串以匹配
{
"HostedVoiceUserJson": [
{
"type": "NamedUser",
"name": "Scott",
"id": "0d2c71cf-52ee-4c50-a974-ea07003df05e",
"cssClass": "NamedUser",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"x": 220,
"y": 200
},
{
"type": "NamedUser",
"name": "Nancy",
"id": "601b0ad9-a0e9-4604-8861-38694a43e0a8",
"cssClass": "NamedUser",
"bgColor": "#DBDDDE",
"color": "#D7D7D7",
"stroke": 1,
"alpha": 1,
"radius": 3,
"x": 220,
"y": 200
}
]
}
当然,我不能一直坐在这里手动更改这些,我需要能够找到让它工作的地方,以便我可以将多种不同的类型一起发布回来。
【问题讨论】:
-
我找到了解决方法,但这只是一种解决方法,它确实解决了我当前的问题,但由于这个问题是一个更广泛的问题,我认为它会为很多人服务很高兴获得比我所拥有的更彻底的解决方案,我保持这个状态。就我的解决方案而言,我创建了一个包含所有类的所有属性的新类,在它位于控制器中之后,我将它们与那里分开。不是最佳的,但目前可以使用。
标签: asp.net-mvc json draw2d draw2d-js