C#如何实现复杂嵌套JSON数据的增删改

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

我在学习中需要根据某条件对嵌套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";

我想要达到的结果

不能foreach,可以用for,调用List类的remove或者removeAt可以从队列中移除对象。
直接替换的话也不能用foreach,也是for,然后直接更改对应下标的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;// _OperationBeanList.Remove
            if (_OperationBeanList.Count > 0)
            {
                foreach (OperationBean b0 in _OperationBeanList)
                {
                    List<OperationBean> _OperationBeanList0 = b0.OperBeanList;
                    if (_OperationBeanList0.Count > 0)
                    {
                        //要删除或者更换列表对象不能用foreach,迭代变量不能直接替换,但是可以修改内部属性值
                        for (var i = 0; i < _OperationBeanList0.Count;i++)
                        {
                            var b1 = _OperationBeanList0[i];
                            if (b1.OperCalculationRules.Length > 0)
                            {
                                b1 = new OperationBean();
                                //对新的b1属性进行赋值或者计算
                                _OperationBeanList0[i] = b1;///////////更新这个下标的对象为新的OperationBean
                            }
                            else
                            {
                                List<OperationBean> _OperationBeanList1 = b1.OperBeanList;
                                if (_OperationBeanList1.Count > 0)
                                {
                                    foreach (OperationBean b2 in _OperationBeanList1)
                                    {

                                    }
                                }
                            }
                        }
                        /*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)
                                    {

                                    }
                                }
                            }
                        }*/
                    }
                }
            }
        }

你可以尝试用帮助类 先读一遍json,读到内存里,修改相应值之后 再进行保存文件。
Newtonsoft.Json.dll
类是这个。

b1 和obj1 类型不等 怎么替换?还是obj1中取一条替换?

            b1 = obj1[0];