问题遇到的现象和发生背景
我在学习中需要根据某条件对嵌套JSON中的实体类进行增删改处理,例如下面的主程序中,如果某一层的OperCalculationRules.Length > 0,我就需要删除这一层的OperationBean,然后添加新的OperationBean来代替,并且新的OperationBean可能是一个OperationBean组(即不止一个OperationBean),其内部嵌套的长度不等。
我想请教的是这种情况下代码如何写?即需要在主程序中实现以下功能:
"//删除b1"
"//需要用obj1替换b1 ,其中obj1是类似于b1的OperationBean组"
问题相关代码,请勿粘贴截图
//主程序
private void x(CalculateTransferBean obj, List<OperationBean> obj1)
{
#region 读取参数
string _DrawingItemNumber = obj.DrawingItemNumber;
string _TemplateNo = obj.TemplateNo;
string _ConfigurationParameter = obj.ConfigurationParameter;
string _RingTemplateNo = obj.RingTemplateNo;
#endregion
List<OperationBean> _OperationBeanList = obj.OperationBeanList;
if (_OperationBeanList.Count > 0)
{
foreach (OperationBean b0 in _OperationBeanList)
{
List<OperationBean> _OperationBeanList0 = b0.OperBeanList;
if (_OperationBeanList0.Count > 0)
{
foreach (OperationBean b1 in _OperationBeanList0)
{
if (b1.OperCalculationRules.Length > 0) //假如存在计算规则
{
//删除b1
//需要用obj1替换b1 ,其中obj1是类似于b1的OperationBean组
}
else
{
List<OperationBean> _OperationBeanList1 = b1.OperBeanList;
if (_OperationBeanList1.Count > 0)
{
foreach (OperationBean b2 in _OperationBeanList1)
{
}
}
}
}
}
}
}
}
//实体类
public class CalculateTransferBean
{
public String MPMProcessNumber { set; get; }
public String TemplateNo { set; get; }
public List<OperationBean> OperationBeanList { set; get; }// 工序集合
}
//实体类
public class OperationBean
{
public String OperNumber { set; get; }// 操作编号
public String OperName { set; get; }// 操作名称
public String OperType { set; get; }// 操作类型
public String OperSymble { set; get; }// 操作代号
public String OperLabel { set; get; }// 操作标签编号
public String OperCalculationRules { set; get; }// 计算规则
public String OperModifyFlag { set; get; }// 是否修改
public String OperDescription { set; get; }// 操作详细说明(返回信息)
public String OperTexingFuhao { set; get; }// 操作特性符号(返回信息)
public List<OperationBean> OperBeanList { set; get; }// 参数集合
}
运行结果及报错内容
我的解答思路和尝试过的方法
b1.OperDescription = "XX";
b1.OperSymble = "AA";