0

我正在使用允许导出 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
                    }
                ]
            }

当然,我不能一直坐在这里手动更改这些,我需要能够找到让它工作的地方,以便我可以将多种不同的类型一起发布回来。

4

1 回答 1

0

看起来您的 JSON 是一个对象数组。您需要同质 JSON 集合才能被 ModelBinder 自动识别。

根据类型,您可以分离 JSON 对象并将它们发送到不同的同类数组中。这样你就可以在 C# 中匹配你的模型类

于 2014-08-12T20:44:53.360 回答