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中,也不用设置。

树立目标,保持活力,gogogo!

C# json反序列化 对象中嵌套数组 (转载) 可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。的更多相关文章

  1. C# json反序列化 对象中嵌套数组 (转载)

    看图: 这里可以看到是二层嵌套!!使用C#如何实现?? 思路:使用list集合实现 → 建立类 → list集合 → 微软的   Newtonsoft.Json  (一款.NET中开源的Json序列化 ...

  2. 关于EF中出现FOREIGNKEY约束可能会导致循环或多重级联路径的问题

    ef中,我们创建外键的时候需要注意,否则会出现标题所示问题. 例:有项目表,项目收藏表,用户表 项目表有如下字段:ProjectId,InputPersonId等 项目收藏表有如下字段:Project ...

  3. struts2:遍历自定义字符串数组,遍历Action实例所引用对象中的数组

    在struts2:OGNL表达式,遍历List.Map集合:投影的使用一文中已经讲述了OGNL遍历List.Map集合等功能. 本文简单写一个遍历数组的示范程序. 1. 遍历自定义字符串数组 < ...

  4. 无法删除对象 '产品',因为该对象正由一个 FOREIGN KEY 约束引用。

    在删除northwindcs表时,发生报错,消息 3726,级别 16,状态 1,第 2 行,无法删除对象 '产品',因为该对象正由一个 FOREIGN KEY 约束引用.此时判断是因为有其他表的外键 ...

  5. 如何向java后台的对象中传数组

    1.后台对象的参数需要是是list对象 /* * copyright : GLOBALROAM Ptd Ltd * VmCreateInfo.java * Author: * zhangpengyan ...

  6. json反序列化对象

    这个是同事研究的wcf中中根据type类型反序列化json的示例 /// <summary> /// json转对象 /// </summary> /// <param ...

  7. 使用jQuery+huandlebars遍历展示对象中的数组

    兼容ie8(很实用,复制过来,仅供技术参考,更详细内容请看源地址:http://www.cnblogs.com/iyangyuan/archive/2013/12/12/3471227.html) & ...

  8. PHP将json或对象转成数组

    今天老大突然给了我一个小任务,给我一个txt文件,里边是很多的json字串,要求将这些字串转换成php中的数组: 于是开足火力,用了将进5分钟的时间完成了任务,代码如下: $jsonStr = fil ...

  9. C# json对象中包含数组对象时,如何存入数据库

    前端创建的的对象例如: C#端这样将数组提取出来存入

随机推荐

  1. 转:深入 AngularUI Router

    原文地址:http://www.ng-newsletter.com/posts/angular-ui-router.html ui-router: https://angular-ui.github. ...

  2. [转]python开发_shelve_完整版

    ''' python中的shelve模块,可以提供一些简单的数据操作 他和python中的dbm很相似. 区别如下: 都是以键值对的形式保存数据,不过在shelve模块中, key必须为字符串,而值可 ...

  3. [uiautomator篇] uiautoviewer 定位不到元素

    定位工具: Uiautomatorviewer 在我们的APP中,只有这一个页面,元素无法加载出来,其它的都没有什么问题.   提示的错误:Error while obtaining UI hiera ...

  4. MySQL binlog_rows_query_log_events在线设置无效

    binlog_rows_query_log_events 对binlog_format=row有效,设为true后可以在binary log中记录原始的语句 官方文档显示binlog_rows_que ...

  5. iOS视图边框的简单做法

    我们绘制UI界面的时候,一般我们做边框是用layer,然后再给它上面添加阴影什么的,我比较喜欢用下面这个方法, UI弄几张边框的图片,用代码给图片拉伸 - (UIImage *)changeBorde ...

  6. xmpp 环境配置

    XMPP框架地址:http://xmpp.org/xmpp-software/libraries/ 配置流程

  7. robotframework安装和配置【转IBM:https://www.ibm.com/developerworks/cn/opensource/os-cn-robot-framework/index.html】

    内容   概览 Robot Framework 介绍 Robot Framework 的安装和配置 RIDE 编辑器介绍 创建测试项目 简单的测试用例的编写 总结 相关主题 评论   Robot Fr ...

  8. 征途(bzoj 4518)

    Description Pine开始了从S地到T地的征途. 从S地到T地的路可以划分成n段,相邻两段路的分界点设有休息站. Pine计划用m天到达T地.除第m天外,每一天晚上Pine都必须在休息站过夜 ...

  9. mode(BZOJ 2456)

    Description 给你一个n个数的数列,其中某个数出现了超过n div 2次即众数,请你找出那个数. Input 第1行一个正整数n.第2行n个正整数用空格隔开. Output 一行一个正整数表 ...

  10. 商务旅行(codevs 1036)

    题目描述 Description 某首都城市的商人要经常到各城镇去做生意,他们按自己的路线去做,目的是为了更好的节约时间. 假设有N个城镇,首都编号为1,商人从首都出发,其他各城镇之间都有道路连接,任 ...