C# json反序列化 对象中嵌套数组 (转载) 可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。
2018-03-29 19:04
961 查看
C# json反序列化 对象中嵌套数组 (转载)
看图:
这里可以看到是二层嵌套!!使用C#如何实现??
思路:使用list集合实现 → 建立类 → list集合 → 微软的 Newtonsoft.Json (一款.NET中开源的Json序列化和反序列化)
sonXMText类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JsonDemo { public class sonXMText { public string xmleixing { get; set; } public string count { get; set; } public string xmtype { get; set; } public string url { get; set; } public string progress { get; set; } public string WaitCount { get; set; } } }
TestInfo类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JsonDemo { public class TestInfo { public string XMText { get; set; } public string XMTYPE { get; set; } public string Count { get; set; } List<sonXMText> sonxmtext = new List<sonXMText>(); public List<sonXMText> sonXMText { get { return sonxmtext; } set { sonxmtext = value; } } } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace JsonDemo { class Program { static void Main(string[] args) { List<TestInfo> listTestinfo = new List<TestInfo>(); TestInfo testinfo = new TestInfo(); testinfo.XMText = "综合交通"; testinfo.XMTYPE = "01"; testinfo.Count = "108"; List<sonXMText> listSonText = new List<sonXMText>(); sonXMText sontext1 = new sonXMText(); sontext1.xmleixing = "市重点交通"; sontext1.xmtype = "32"; sontext1.count = "20"; sontext1.url = "../ProjectManage/Pagesilding/ZongHeJiaoTong/Zonghetra/Zonghetra_List.aspx?xmtype=0101"; sontext1.progress = "52.61"; sontext1.WaitCount = "27"; sonXMText sontext2 = new sonXMText(); sontext1.xmleixing = "支路网建设"; sontext1.xmtype = "32"; sontext1.count = "20"; sontext1.url = "../ProjectManage/Pagesilding/ZongHeJiaoTong/Zonghetra/Zonghetra_List.aspx?xmtype=0101"; sontext1.progress = "52.61"; sontext1.WaitCount = "27"; listSonText.Add(sontext1); listSonText.Add(sontext2); testinfo.sonXMText = listSonText; listTestinfo.Add(testinfo); string aa = Newtonsoft.Json.JsonConvert.SerializeObject(listTestinfo); File.AppendAllText(@"C:\mymiao.txt", aa, Encoding.UTF8); } } }
来源:https://www.cnblogs.com/panmy/p/5924324.html
可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。
错误提示:可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。
原因:自表连接(同一张表自己连接自己)不允许级联删除和级联更新。
一、sql语句
create table DataClass ( CID nvarchar(6) not null, ParentID nvarchar(6) null, CNAME nvarchar(50) not null, ENAME nvarchar(50) not null, DISCRIB nvarchar(200) null, DATATYPE smallint null, constraint PK_DATACLASS primary key (CID) ) go create unique index IX_DataClass on DataClass ( ENAME ASC ) go alter table DataClass drop constraint FK_DataType_self --报错:可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。 --alter table DataClass -- add constraint FK_DataType_self foreign key (ParentID) -- references DataClass (CID) -- on update cascade --go --改为: alter table DataClass add constraint FK_DataType_self foreign key (ParentID) references DataClass (CID) on update NO ACTION go
二、发现
on update NO ACTION 其实可以省略,因为默认有这种机制。
内容如下:
USE [Ecology]
GO
ALTER TABLE [dbo].[DataClass] WITH CHECK ADD CONSTRAINT [FK_DataType_self] FOREIGN KEY([ParentID])
REFERENCES [dbo].[DataClass] ([CID])
GO
ALTER TABLE [dbo].[DataClass] CHECK CONSTRAINT [FK_DataType_self]
GO
sqlserver自动省略了 on update NO ACTION
sql约束可以修改为:
alter table DataClass add constraint FK_DataType_self foreign key (ParentID) references DataClass (CID) go
在PowderDesigner中,也不用设置。
相关文章推荐
- 可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。
- Entity Framework 使用Code First 处理多个表关系时的错误 “将 FOREIGN KEY 约束 'FK_dbo.' 引入表 ' ' 可能会导致循环或多重级联路径”
- C# json反序列化 对象中嵌套数组 (转载)
- 级联引用完整性约束ON DELETE { NO ACTION | CASCADE | SET NULL | SET DEFAULT }
- 嵌套 JSON 对象中的数组使用 for-in 来循环访问每个数组
- 转载C# 对象转Json序列化
- C# 对json对象嵌套数组
- c# json数组循环给list对象实体 值
- C#反序列化JSON数组对象
- C# DataTable 对象转换成Json时 出现 序列化类型为“System.Reflection.Module”的对象时检测到循环引用 的错误!
- element UI Cascader 级联选择器 编辑 修改 数组 路径 问题(转载)
- C# json 序列化 匿名对象序列号 指定对象序列化
- json的作用:按规定格式保存js语言中的一组数据并转换为字符串(json是种特殊的容器,一般保存对象和数组数据(可以嵌套),并把它们装换为字符串在网络中传输?))
- js 按指定属性给对象数组排序(json数组)
- 将行信息带入后台或者其他页面,如何迭代循环输出form中指定list中的对象
- js将form表单序列化[json字符串、数组、对象]
- C#将JSON字符串对象序列化与反序列化
- C# 对象序列化成xml格式的时候指定日期型(DateTime)属性的序列化格式
- 使用NewtonSoft.JSON.dll来序列化和发序列化对象(转载)
- JSON序列化的注意(数组,字典,自定义对象的序列化)