weixin_40576400
2021-11-25 21:02
采纳率: 84%
浏览 35
已结题

.Net Core3.1 webapi如何接受java调用程序传入的复杂对象 Beanjson

问题遇到的现象和发生背景

在学习JAVA调用.Net Core3.1 webapi时,不知道webapi如何接受较为复杂的对象数据,请专家指点。
我尝试写调用代码,不知道如何往下写了。
数据格式如下:

问题相关代码,请勿粘贴截图

这是java调用webapi时发送数据格式:

CalculateTransferBeanjson:
{
"MPMProcessNumber":"CPZ-005-001"
,"TemplateNo":"CPZ-005"
,"DrawingItemNumber":"M-CPZ130-571"
,"PartNumber":"M-CPZ130-571"
,"PartName":"氛围法尔"
,"Structure":"321"
,"Customer":"24324斯"
,"RingType":"3"
,"SteelStrip":"123"
,"ConfigurationParameter":"xxx "
,"ConfigurationRule":"要求xxx "
,"RingTemplateNo":"123"
,"RingTemplateValue":"234"
,"OperationBeanList":[
    {"OperationNumber":"0000002505"
    ,"OperationLabel":"0010"
    ,"CalculationRules":""
    ,"OperationName":"份洗"
    ,"OperationType":"工序"
    ,"OperationBeanList":[
        {"OperationNumber":"0000002507"
        ,"OperationLabel":"0020"
        ,"CalculationRules":"计算方法xxx"
        ,"OperationName":"清洁度"
        ,"OperationType":"参数"}
        ]
    },
    {"OperationNumber":"0000002508"
    ,"OperationLabel":"0020"
    ,"CalculationRules":""
    ,"OperationName":"磷化"
    ,"OperationType":"工序"
    ,"OperationBeanList":[
        {"OperationNumber":"0000002509"
        ,"OperationLabel":"0010"
        ,"CalculationRules":"计算方法xxx"
        ,"OperationName":"外观"
        ,"OperationType":"参数"}
        ]
    },
    {"OperationNumber":"0000002510"
    ,"OperationLabel":"0030"
    ,"CalculationRules":""
    ,"OperationName":"成观"
    ,"OperationType":"工序"
    },
    {"OperationNumber":"0000002511"
    ,"OperationLabel":"0040"
    ,"CalculationRules":""
    ,"OperationName":"检隙"
    ,"OperationType":"工序"
    ,"OperationBeanList":[
        {"OperationNumber":"0000002512"
        ,"OperationLabel":"0010"
        ,"CalculationRules":"计算方法xxx"
        ,"OperationName":"间隙:"
        ,"OperationType":"参数"}]
    },
    {"OperationNumber":"0000002514"
    ,"OperationLabel":"0050"
    ,"CalculationRules":""
    ,"OperationName":"检外圆"
    ,"OperationType":"工序"
    },
    {"OperationNumber":"0000002515"
    ,"OperationLabel":"0060"
    ,"CalculationRules":""
    ,"OperationName":"打标"
    ,"OperationType":"工序"
    ,"OperationBeanList":[
        {"OperationNumber":"0000002516"
        ,"OperationLabel":"0010"
        ,"CalculationRules":"计算方法xxx"
        ,"OperationName":"打标方向"
        ,"OperationType":"参数"
        },
        {"OperationNumber":"0000002517"
        ,"OperationLabel":"0020"
        ,"CalculationRules":"计算方法xxx"
        ,"OperationName":"打标距开口左侧"
        ,"OperationType":"参数"
        },
        {"OperationNumber":"0000002518"
        ,"OperationLabel":"0030"
        ,"CalculationRules":"计算方法xxx"
        ,"OperationName":"打标距开口右侧"
        ,"OperationType":"参数"
        },
        {"OperationNumber":"0000002519"
        ,"OperationLabel":"0050"
        ,"CalculationRules":"计算方法xxx"
        ,"OperationName":"外观"
        ,"OperationType":"参数"
        },
        {"OperationNumber":"0000002520"
        ,"OperationLabel":"0060"
        ,"CalculationRules":"计算方法xxx"
        ,"OperationName":"打标左侧内容"
        ,"OperationType":"参数"
        },
        {"OperationNumber":"0000002521"
        ,"OperationLabel":"0070"
        ,"CalculationRules":"计算方法xxx"
        ,"OperationName":"打标右侧内容"
        ,"OperationType":"参数"
        }
    ]
    }
]
}

运行结果及报错内容
我的解答思路和尝试过的方法

我尝试写的webapi接受代码如下,写了一部分,不知道如何往下写了。

[HttpPost("PostSurface")]
        public IActionResult GetBeanjson([FromForm] dynamic obj)
        {
            #region  读取传入的参数
            dynamic objdyn = JsonConvert.DeserializeObject(Convert.ToString(obj));
            string _MPMProcessNumber = Convert.ToString(objdyn.MPMProcessNumber);                   
            string _TemplateNo = Convert.ToString(objdyn.TemplateNo);                 
            string _DrawingItemNumber = Convert.ToString(objdyn.DrawingItemNumber);                  
            string _PartNumber = Convert.ToString(objdyn.PartNumber);               
            string _PartName = Convert.ToString(objdyn.PartName);                 
            string _Structure = Convert.ToString(objdyn.Structure);                     
            string _Customer = Convert.ToString(objdyn.Customer);                
            string _RingType = Convert.ToString(objdyn.RingType);           
            string _SteelStrip = Convert.ToString(objdyn.SteelStrip);            
            string _ConfigurationParameter = Convert.ToString(objdyn.ConfigurationParameter);      
            string _ConfigurationRule = Convert.ToString(objdyn.ConfigurationRule);                         
            string _RingTemplateNo = Convert.ToString(objdyn.RingTemplateNo);                  
            string _RingTemplateValue = Convert.ToString(objdyn.RingTemplateValue);       
??????

}

我想要达到的结果
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • CSDN专家-showbo 2021-11-25 21:13
    最佳回答

    获取OperationBeanList吗?这个是数组,可以直接遍历获取

    
                foreach (var r in obj.OperationBeanList) {
                    //(r.OperationNumber);
                    //(r.OperationLabel);
                }
    
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题