在.NetFramework中使用Microsoft.Extensions.Configuration 读取Json和XML

这篇具有很好参考价值的文章主要介绍了在.NetFramework中使用Microsoft.Extensions.Configuration 读取Json和XML。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

//需要安装 Microsoft.Extensions.Configuration;
//Microsoft.Extensions.Configuration.json
//Microsoft.Extensions.Configuration.xml
//Microsoft.Extensions.Configuration.Binder;

//注意: json 的key中不能出现冒号":"
//XML的 Atrribute中不能出现关键词 “Name”, 且不能使用根节点(从第一个子节点开始)

using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

//需要安装 Microsoft.Extensions.Configuration;
//Microsoft.Extensions.Configuration.json
//Microsoft.Extensions.Configuration.xml
//Microsoft.Extensions.Configuration.Binder;

//注意: json 的key中不能出现冒号":"
//XML的 Atrribute中不能出现关键词 "Name", 且不能使用根节点(从第一个子节点开始)
namespace XMLFrameworkDemon
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ConfigurationBuilder cfgbuilder = new ConfigurationBuilder();
            cfgbuilder.AddXmlFile("cfg.xml");
            IConfigurationRoot root = cfgbuilder.Build(); ;
            string name = root.GetSection("NodeClass:ModbusNode:ModbusGroup:NameXML").Value;
            //string variable = root.GetSection("NodeClass:ModbusNode:Variable:0:NameXML").Value; //不行


            ConfigurationBuilder cfgJsonbuilder = new ConfigurationBuilder();
            cfgJsonbuilder.AddJsonFile("VariableNode.json");
            IConfigurationRoot rootJson = cfgJsonbuilder.Build();
            string nameJson = rootJson.GetSection("NodeClass:ModbusNode:ModbusGroup:Name").Value;

            Console.WriteLine("=======XML===========");
            Console.WriteLine(name);
            Console.WriteLine("========Json==========");
            Console.WriteLine(nameJson);

            Console.WriteLine("        ");
            Console.WriteLine("=======使用extensions.Configuration.Binder获取变量===========");
            Console.WriteLine("        ");
            Variable variablexml = root.GetSection("NodeClass:ModbusNode:ModbusGroup:Variable:2").Get<Variable>();
            VariableJson variableJson = rootJson.GetSection("NodeClass:ModbusNode:ModbusGroup:Variable:1").Get<VariableJson>();

            Console.WriteLine("======XML============");
            Console.WriteLine(variablexml.NameXML);
            Console.WriteLine("=======Json===========");
            Console.WriteLine(variableJson.Description);
            Console.ReadKey();

            //结果:
            /*
                =======XML===========
                测试1: 长度为寄存器个数
                ========Json==========
                保持寄存器长度为寄存器个数

                =======使用extensions.Configuration.Binder获取变量===========

                ======XML============
                Float3
                =======Json===========
                40003-40004

             */
        }
    }
}

        //结果:
        /*
            =======XML===========
            测试1: 长度为寄存器个数
            ========Json==========
            保持寄存器长度为寄存器个数

            =======使用extensions.Configuration.Binder获取变量===========

            ======XML============
            Float3
            =======Json===========
            40003-40004

         */

实体类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XMLFrameworkDemon
{
    public class Variable
    {

        public string NameXML { get; set; }
        public string Description { get; set; }
        public string Type { get; set; }
        public string VarAddress { get; set; }
        public string Scale { get; set; }
        public string Offset { get; set; }
        public string Start { get; set; }
        public string AccessProperty { get; set; }
        public string AlarmEnable { get; set; }
        public string ArchiveEnable { get; set; }
        public string SetLimitEnable { get; set; }
        public string AlarmType { get; set; }
        public string DiscreteAlarmType { get; set; }
        public string DiscreteAlarmNote { get; set; }
        public string LoLoAlarmEnable { get; set; }
        public string LoLoAlarmValue { get; set; }
        public string LoLoAlarmPriority { get; set; }
        public string LoLoAlarmNote { get; set; }
        public string LowAlarmEnable { get; set; }
        public string LowAlarmValue { get; set; }
        public string LowAlarmPriority { get; set; }
        public string LowAlarmNote { get; set; }
        public string HighAlarmEnable { get; set; }
        public string HighAlarmValue { get; set; }
        public string HighAlarmPriority { get; set; }
        public string HighAlarmNote { get; set; }
        public string HiHiAlarmEnable { get; set; }
        public string HiHiAlarmValue { get; set; }
        public string HiHiAlarmPriority { get; set; }
        public string HiHiAlarmNote { get; set; }
        public string ArchivePeriod { get; set; }
        public string SetLimitMax { get; set; }
        public string SetLimitMin { get; set; }
        public string VarType { get; set; }
    }
}

using System;
using System.Collections.Generic;
using System.Text;

namespace XMLFrameworkDemon
{
    public class VariableJson
    {
        public long Id { get; set; }
        public string Number { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public string Type { get; set; }
        public string VarAddress { get; set; }
        public string Scale { get; set; }
        public string Offset { get; set; }
        public string Start { get; set; }
        public string AccessProperty { get; set; }
        public string AlarmEnable { get; set; }
        public string ArchiveEnable { get; set; }
        public string SetLimitEnable { get; set; }
        public string AlarmType { get; set; }
        public string DiscreteAlarmType { get; set; }
        public string DiscreteAlarmPriority { get; set; }
        public string DiscreteAlarmNote { get; set; }
        public string LoLoAlarmEnable { get; set; }
        public string LoLoAlarmValue { get; set; }
        public string LoLoAlarmPriority { get; set; }
        public string LoLoAlarmNote { get; set; }
        public string LowAlarmEnable { get; set; }
        public string LowAlarmValue { get; set; }
        public string LowAlarmPriority { get; set; }
        public string LowAlarmNote { get; set; }
        public string HighAlarmEnable { get; set; }
        public string HighAlarmValue { get; set; }
        public string HighAlarmPriority { get; set; }
        public string HighAlarmNote { get; set; }
        public string HiHiAlarmEnable { get; set; }
        public string HiHiAlarmValue { get; set; }
        public string HiHiAlarmPriority { get; set; }
        public string HiHiAlarmNote { get; set; }
        public string ArchivePeriod { get; set; }
        public string SetLimitMax { get; set; }
        public string SetLimitMin { get; set; }
        public string VarType { get; set; }
        public string StoreType { get; set; }
        public string InsertTime { get; set; }
        public string Value { get; set; }
        public long ModbusGroupId { get; set; }
    }
}


XML:

<Settings>
	<NodeClass NameXML="Modbus客户端" Description="Modbus相关客户端">
		<ModbusNode NameXML="Modbus TCP Client" Description="1#ZG上位机测试" ModbusType="2000" ConnectTimeOut="2000" CreateTime="2022-03-07 21:18:29" ReConnectTime="5000" InstallationDate="2022-03-07 21:18:29" IsActive="True" MaxErrorTimes="1" KeyWay="VarName" UseAlarmCheck="True" ServerURL="127.0.0.1" Port="502" DataFormat="ABCD">
			<ModbusGroup NameXML="测试1: 长度为寄存器个数" Description="40000-40005" Type="ModbusTCP" StoreArea="保持寄存器" Length="9" Start="0" SlaveID="1" IsActive="true">
				<Variable NameXML="Float1" Description="40001-40002" Type="ModbusTCP" VarAddress="0" Scale="1" Offset="0" Start="0" AccessProperty="读写" AlarmEnable="True" ArchiveEnable="True" SetLimitEnable="True" AlarmType="True" DiscreteAlarmType="False" DiscreteAlarmPriority="0" DiscreteAlarmNote="" LoLoAlarmEnable="True" LoLoAlarmValue="0" LoLoAlarmPriority="0" LoLoAlarmNote="40000-40001低低报警" LowAlarmEnable="True" LowAlarmValue="20" LowAlarmPriority="0" LowAlarmNote="40000-40001低报警" HighAlarmEnable="True" HighAlarmValue="80" HighAlarmPriority="0" HighAlarmNote="40000-40001高报警" HiHiAlarmEnable="True" HiHiAlarmValue="100" HiHiAlarmPriority="0" HiHiAlarmNote="40000-40001高高报警" ArchivePeriod="80" SetLimitMax="100" SetLimitMin="0" VarType="Float" />
				<Variable NameXML="Float2" Description="40003-40004" Type="ModbusTCP" VarAddress="2" Scale="1" Offset="0" Start="0" AccessProperty="读写" AlarmEnable="True" ArchiveEnable="True" SetLimitEnable="True" AlarmType="True" DiscreteAlarmType="False" DiscreteAlarmPriority="0" DiscreteAlarmNote="" LoLoAlarmEnable="True" LoLoAlarmValue="0" LoLoAlarmPriority="0" LoLoAlarmNote="40002-40003低低报警" LowAlarmEnable="True" LowAlarmValue="20" LowAlarmPriority="0" LowAlarmNote="40002-40003低报警" HighAlarmEnable="True" HighAlarmValue="80" HighAlarmPriority="0" HighAlarmNote="40002-40003高报警" HiHiAlarmEnable="True" HiHiAlarmValue="100" HiHiAlarmPriority="0" HiHiAlarmNote="40002-40003高高报警" ArchivePeriod="80" SetLimitMax="100" SetLimitMin="0" VarType="Float" />
				<Variable NameXML="Float3" Description="40005-40006" Type="ModbusTCP" VarAddress="4" Scale="1" Offset="0" Start="0" AccessProperty="读写" AlarmEnable="True" ArchiveEnable="True" SetLimitEnable="True" AlarmType="True" DiscreteAlarmType="False" DiscreteAlarmPriority="0" DiscreteAlarmNote="" LoLoAlarmEnable="True" LoLoAlarmValue="0" LoLoAlarmPriority="0" LoLoAlarmNote="40004-40005低低报警" LowAlarmEnable="True" LowAlarmValue="20" LowAlarmPriority="0" LowAlarmNote="40004-40005低报警" HighAlarmEnable="True" HighAlarmValue="80" HighAlarmPriority="0" HighAlarmNote="40004-40005高报警" HiHiAlarmEnable="True" HiHiAlarmValue="100" HiHiAlarmPriority="0" HiHiAlarmNote="40004-40005高高报警" ArchivePeriod="80" SetLimitMax="100" SetLimitMin="0" VarType="Float" />
				<Variable NameXML="Ushort1" Description="40007" Type="ModbusTCP" VarAddress="6" Scale="1" Offset="0" Start="0" AccessProperty="读写" AlarmEnable="True" ArchiveEnable="True" SetLimitEnable="True" AlarmType="True" DiscreteAlarmType="False" DiscreteAlarmPriority="0" DiscreteAlarmNote="" LoLoAlarmEnable="True" LoLoAlarmValue="0" LoLoAlarmPriority="0" LoLoAlarmNote="具体的通讯变量地址及类型低低报警" LowAlarmEnable="True" LowAlarmValue="20" LowAlarmPriority="0" LowAlarmNote="具体的通讯变量地址及类型低报警" HighAlarmEnable="True" HighAlarmValue="80" HighAlarmPriority="0" HighAlarmNote="具体的通讯变量地址及类型高报警" HiHiAlarmEnable="True" HiHiAlarmValue="100" HiHiAlarmPriority="0" HiHiAlarmNote="具体的通讯变量地址及类型高高报警" ArchivePeriod="0" SetLimitMax="100" SetLimitMin="0" VarType="UShort" />
				<Variable NameXML="Ushort2" Description="40008" Type="ModbusTCP" VarAddress="7" Scale="1" Offset="0" Start="0" AccessProperty="读写" AlarmEnable="True" ArchiveEnable="True" SetLimitEnable="True" AlarmType="True" DiscreteAlarmType="False" DiscreteAlarmPriority="0" DiscreteAlarmNote="" LoLoAlarmEnable="True" LoLoAlarmValue="0" LoLoAlarmPriority="0" LoLoAlarmNote="Ushort2低低报警" LowAlarmEnable="True" LowAlarmValue="20" LowAlarmPriority="0" LowAlarmNote="Ushort2低报警" HighAlarmEnable="True" HighAlarmValue="80" HighAlarmPriority="0" HighAlarmNote="Ushort2高报警" HiHiAlarmEnable="True" HiHiAlarmValue="100" HiHiAlarmPriority="0" HiHiAlarmNote="Ushort2高高报警" ArchivePeriod="80" SetLimitMax="100" SetLimitMin="0" VarType="UShort" />
				<Variable NameXML="Bool1" Description="40009.0" Type="ModbusTCP" VarAddress="8.0" Scale="1" Offset="0" Start="0" AccessProperty="读写" AlarmEnable="True" ArchiveEnable="False" SetLimitEnable="True" AlarmType="False" DiscreteAlarmType="False" DiscreteAlarmPriority="0" DiscreteAlarmNote="" LoLoAlarmEnable="False" LoLoAlarmValue="0" LoLoAlarmPriority="0" LoLoAlarmNote="" LowAlarmEnable="False" LowAlarmValue="0" LowAlarmPriority="0" LowAlarmNote="" HighAlarmEnable="False" HighAlarmValue="0" HighAlarmPriority="0" HighAlarmNote="" HiHiAlarmEnable="False" HiHiAlarmValue="0" HiHiAlarmPriority="0" HiHiAlarmNote="" SetLimitMax="100" SetLimitMin="0" VarType="Bool" />
				<Variable NameXML="Bool2" Description="40009.1" Type="ModbusTCP" VarAddress="8.1" Scale="1" Offset="0" Start="0" AccessProperty="读写" AlarmEnable="True" ArchiveEnable="False" SetLimitEnable="True" AlarmType="False" DiscreteAlarmType="False" DiscreteAlarmPriority="0" DiscreteAlarmNote="" LoLoAlarmEnable="False" LoLoAlarmValue="0" LoLoAlarmPriority="0" LoLoAlarmNote="" LowAlarmEnable="False" LowAlarmValue="0" LowAlarmPriority="0" LowAlarmNote="" HighAlarmEnable="False" HighAlarmValue="0" HighAlarmPriority="0" HighAlarmNote="" HiHiAlarmEnable="False" HiHiAlarmValue="0" HiHiAlarmPriority="0" HiHiAlarmNote="" SetLimitMax="100" SetLimitMin="0" VarType="Bool" />
				<Variable NameXML="Bool3" Description="40009.2" Type="ModbusTCP" VarAddress="8.2" Scale="1" Offset="0" Start="0" AccessProperty="读写" AlarmEnable="True" ArchiveEnable="False" SetLimitEnable="True" AlarmType="False" DiscreteAlarmType="False" DiscreteAlarmPriority="0" DiscreteAlarmNote="" LoLoAlarmEnable="False" LoLoAlarmValue="0" LoLoAlarmPriority="0" LoLoAlarmNote="" LowAlarmEnable="False" LowAlarmValue="0" LowAlarmPriority="0" LowAlarmNote="" HighAlarmEnable="False" HighAlarmValue="0" HighAlarmPriority="0" HighAlarmNote="" HiHiAlarmEnable="False" HiHiAlarmValue="0" HiHiAlarmPriority="0" HiHiAlarmNote="" SetLimitMax="100" SetLimitMin="0" VarType="Bool" />
			</ModbusGroup>
		</ModbusNode>
	</NodeClass>
</Settings>

Json:文章来源地址https://www.toymoban.com/news/detail-509801.html

{
    "ConnectionStrings": {
        "SqliteConnectionString": "Data Source=E:\\Csharp\\EF6Demon\\EF6Demon\\bin\\Debug\\net6.0-windows\\Database\\DbSqlite.db",
        "MySQLConnectionString": "server=192.168.85.102; database=OneToMany; uid=root; pwd=123456;"
    },
    "NodeClass": {
        "Id": 1,
        "Name": "ModbusClent",
        "Description": "Modbus相关客户端",
        "ModbusNode": {
            "Id": 1,
            "NodeClassId": 1,
            "Name": "ModbusTCPClient",
            "Description": "1#ZG上位机测试",
            "ModbusType": "2000",
            "ConnectTimeOut": "2000",
            "CreateTime": "0",
            "ReConnectTime": "5000",
            "IsActive": "True",
            "MaxErrorTimes": "1",
            "KeyWay": "VarName",
            "UseAlarmCheck": "True",
            "ServerURL": "127.0.0.1",
            "Port": "502",
            "DataFormat": "ABCD",
            "VarNum": "6",
            "ModbusGroup": {
                "Id": 1,
                "Name": "保持寄存器长度为寄存器个数",
                "Description": "40001-40010",
                "Type": "ModbusTCP",
                "StoreArea": "40000",
                "Length": "10",
                "Start": "0",
                "SlaveID": "1",
                "IsActive": "true",
                "ModbusNodeId": 1,
                "Variable": [
                    {
                        "Id": 1,
                        "Number": "1",
                        "Name": "Float1",
                        "Description": "40001-40002",
                        "Type": "ModbusTCP",
                        "VarAddress": 0,
                        "Scale": "1",
                        "Offset": "0",
                        "Start": "0",
                        "AccessProperty": "读写",
                        "AlarmEnable": "True",
                        "ArchiveEnable": "True",
                        "SetLimitEnable": "True",
                        "AlarmType": "True",
                        "DiscreteAlarmType": "False",
                        "DiscreteAlarmPriority": "0",
                        "DiscreteAlarmNote": "null",
                        "LoLoAlarmEnable": "True",
                        "LoLoAlarmValue": "0",
                        "LoLoAlarmPriority": "0",
                        "LoLoAlarmNote": "40001-40002低低报警",
                        "LowAlarmEnable": "True",
                        "LowAlarmValue": "20",
                        "LowAlarmPriority": "0",
                        "LowAlarmNote": "40001-40002低报警",
                        "HighAlarmEnable": "True",
                        "HighAlarmValue": "80",
                        "HighAlarmPriority": "0",
                        "HighAlarmNote": "40001-40002高报警",
                        "HiHiAlarmEnable": "True",
                        "HiHiAlarmValue": "100",
                        "HiHiAlarmPriority": "0",
                        "HiHiAlarmNote": "40001-40002高高报警",
                        "ArchivePeriod": "80",
                        "SetLimitMax": "100",
                        "SetLimitMin": "0",
                        "VarType": "Float",
                        "StoreType": "03 Holding Register(4x)",
                        "InsertTime": "0",
                        "Value": "0",
                        "ModbusGroupId": 1
                    },
                    {
                        "Id": 2,
                        "Number": "2",
                        "Name": "Float2",
                        "Description": "40003-40004",
                        "Type": "ModbusTCP",
                        "VarAddress": 2,
                        "Scale": "1",
                        "Offset": "0",
                        "Start": "0",
                        "AccessProperty": "读写",
                        "AlarmEnable": "True",
                        "ArchiveEnable": "True",
                        "SetLimitEnable": "True",
                        "AlarmType": "True",
                        "DiscreteAlarmType": "False",
                        "DiscreteAlarmPriority": "0",
                        "DiscreteAlarmNote": "null",
                        "LoLoAlarmEnable": "True",
                        "LoLoAlarmValue": "0",
                        "LoLoAlarmPriority": "0",
                        "LoLoAlarmNote": "40003-40004低低报警",
                        "LowAlarmEnable": "True",
                        "LowAlarmValue": "20",
                        "LowAlarmPriority": "0",
                        "LowAlarmNote": "40003-40004低报警",
                        "HighAlarmEnable": "True",
                        "HighAlarmValue": "80",
                        "HighAlarmPriority": "0",
                        "HighAlarmNote": "40003-40004高报警",
                        "HiHiAlarmEnable": "True",
                        "HiHiAlarmValue": "100",
                        "HiHiAlarmPriority": "0",
                        "HiHiAlarmNote": "40003-40004高高报警",
                        "ArchivePeriod": "80",
                        "SetLimitMax": "100",
                        "SetLimitMin": "0",
                        "VarType": "Float",
                        "StoreType": "03 Holding Register(4x)",
                        "InsertTime": "0",
                        "Value": "0",
                        "ModbusGroupId": 1
                    },
                    {
                        "Id": 3,
                        "Number": "3",
                        "Name": "Float3",
                        "Description": "40005-40006",
                        "Type": "ModbusTCP",
                        "VarAddress": 4,
                        "Scale": "1",
                        "Offset": "0",
                        "Start": "0",
                        "AccessProperty": "读写",
                        "AlarmEnable": "True",
                        "ArchiveEnable": "True",
                        "SetLimitEnable": "True",
                        "AlarmType": "True",
                        "DiscreteAlarmType": "False",
                        "DiscreteAlarmPriority": "0",
                        "DiscreteAlarmNote": "null",
                        "LoLoAlarmEnable": "True",
                        "LoLoAlarmValue": "0",
                        "LoLoAlarmPriority": "0",
                        "LoLoAlarmNote": "40005-40006低低报警",
                        "LowAlarmEnable": "True",
                        "LowAlarmValue": "20",
                        "LowAlarmPriority": "0",
                        "LowAlarmNote": "40005-40006低报警",
                        "HighAlarmEnable": "True",
                        "HighAlarmValue": "80",
                        "HighAlarmPriority": "0",
                        "HighAlarmNote": "40005-40006高报警",
                        "HiHiAlarmEnable": "True",
                        "HiHiAlarmValue": "100",
                        "HiHiAlarmPriority": "0",
                        "HiHiAlarmNote": "40005-40006高高报警",
                        "ArchivePeriod": "80",
                        "SetLimitMax": "100",
                        "SetLimitMin": "0",
                        "VarType": "Float",
                        "StoreType": "03 Holding Register(4x)",
                        "InsertTime": "0",
                        "Value": "0",
                        "ModbusGroupId": 1
                    },
                    {
                        "Id": 4,
                        "Number": "4",
                        "Name": "Float4",
                        "Description": "40007-40008",
                        "Type": "ModbusTCP",
                        "VarAddress": 6,
                        "Scale": "1",
                        "Offset": "0",
                        "Start": "0",
                        "AccessProperty": "读写",
                        "AlarmEnable": "True",
                        "ArchiveEnable": "True",
                        "SetLimitEnable": "True",
                        "AlarmType": "True",
                        "DiscreteAlarmType": "False",
                        "DiscreteAlarmPriority": "0",
                        "DiscreteAlarmNote": "null",
                        "LoLoAlarmEnable": "True",
                        "LoLoAlarmValue": "0",
                        "LoLoAlarmPriority": "0",
                        "LoLoAlarmNote": "40003-40004低低报警",
                        "LowAlarmEnable": "True",
                        "LowAlarmValue": "20",
                        "LowAlarmPriority": "0",
                        "LowAlarmNote": "40003-40004低报警",
                        "HighAlarmEnable": "True",
                        "HighAlarmValue": "80",
                        "HighAlarmPriority": "0",
                        "HighAlarmNote": "40003-40004高报警",
                        "HiHiAlarmEnable": "True",
                        "HiHiAlarmValue": "100",
                        "HiHiAlarmPriority": "0",
                        "HiHiAlarmNote": "40003-40004高高报警",
                        "ArchivePeriod": "80",
                        "SetLimitMax": "100",
                        "SetLimitMin": "0",
                        "VarType": "Float",
                        "StoreType": "03 Holding Register(4x)",
                        "InsertTime": "0",
                        "Value": "0",
                        "ModbusGroupId": 1
                    },
                    {
                        "Id": 5,
                        "Number": "5",
                        "Name": "Ushort1",
                        "Description": "40009",
                        "Type": "ModbusTCP",
                        "VarAddress": 8,
                        "Scale": "1",
                        "Offset": "0",
                        "Start": "0",
                        "AccessProperty": "读写",
                        "AlarmEnable": "True",
                        "ArchiveEnable": "True",
                        "SetLimitEnable": "True",
                        "AlarmType": "True",
                        "DiscreteAlarmType": "False",
                        "DiscreteAlarmPriority": "0",
                        "DiscreteAlarmNote": "null",
                        "LoLoAlarmEnable": "True",
                        "LoLoAlarmValue": "0",
                        "LoLoAlarmPriority": "0",
                        "LoLoAlarmNote": "40009低低报警",
                        "LowAlarmEnable": "True",
                        "LowAlarmValue": "20",
                        "LowAlarmPriority": "0",
                        "LowAlarmNote": "40009低报警",
                        "HighAlarmEnable": "True",
                        "HighAlarmValue": "80",
                        "HighAlarmPriority": "0",
                        "HighAlarmNote": "40009高报警",
                        "HiHiAlarmEnable": "True",
                        "HiHiAlarmValue": "100",
                        "HiHiAlarmPriority": "0",
                        "HiHiAlarmNote": "40009高高报警",
                        "ArchivePeriod": "80",
                        "SetLimitMax": "100",
                        "SetLimitMin": "0",
                        "VarType": "UShort",
                        "StoreType": "03 Holding Register(4x)",
                        "InsertTime": "0",
                        "Value": "0",
                        "ModbusGroupId": 1
                    },
                    {
                        "Id": 6,
                        "Number": "6",
                        "Name": "Ushort2",
                        "Description": "40010",
                        "Type": "ModbusTCP",
                        "VarAddress": 9,
                        "Scale": "1",
                        "Offset": "0",
                        "Start": "0",
                        "AccessProperty": "读写",
                        "AlarmEnable": "True",
                        "ArchiveEnable": "True",
                        "SetLimitEnable": "True",
                        "AlarmType": "True",
                        "DiscreteAlarmType": "False",
                        "DiscreteAlarmPriority": "0",
                        "DiscreteAlarmNote": "null",
                        "LoLoAlarmEnable": "True",
                        "LoLoAlarmValue": "0",
                        "LoLoAlarmPriority": "0",
                        "LoLoAlarmNote": "40009低低报警",
                        "LowAlarmEnable": "True",
                        "LowAlarmValue": "20",
                        "LowAlarmPriority": "0",
                        "LowAlarmNote": "40009低报警",
                        "HighAlarmEnable": "True",
                        "HighAlarmValue": "80",
                        "HighAlarmPriority": "0",
                        "HighAlarmNote": "40009高报警",
                        "HiHiAlarmEnable": "True",
                        "HiHiAlarmValue": "100",
                        "HiHiAlarmPriority": "0",
                        "HiHiAlarmNote": "40009高高报警",
                        "ArchivePeriod": "80",
                        "SetLimitMax": "100",
                        "SetLimitMin": "0",
                        "VarType": "UShort",
                        "StoreType": "03 Holding Register(4x)",
                        "InsertTime": "0",
                        "Value": "0",
                        "ModbusGroupId": 1
                    }
                ]
            }
        }
    }
}

到了这里,关于在.NetFramework中使用Microsoft.Extensions.Configuration 读取Json和XML的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 聊一聊如何整合Microsoft.Extensions.DependencyInjection和Castle.Core(完结篇)

    还是先上代码, 这是基础版本我们要达成的目标,仅需定义一个特性即可完成拦截的目标 如上是我们定义的拦截器基类,我们想要达到的目标是,只要继承该基类,并覆写InterceptAsync 方法即可实现具有特定功能的拦截类,而容器会自动代理到该拦截类,实现拦截。 这里要感

    2024年02月02日
    浏览(40)
  • 聊一聊为什么我要整合Microsoft.Extensions.DependencyInjection和Castle.Core

    如果用到动态代理,大家可能会有几种选择,排到前列的是Autofac+Castle、AspectCore和DoraInterception, 我将从我当时研究的经历,以及我遇到的场景,为大家展示下 聊一聊我为什么要费时费力的整合Microsoft.Extensions.DependencyInjection和Castle.Core 直接上源码 如上所示的接口定义了一个事

    2024年02月01日
    浏览(65)
  • 不要用第三方日志包了Microsoft.Extensions.Logging功能就很强大

    在.NET中, Microsoft.Extensions.Logging是一个广泛使用的日志库,用于记录应用程序的日志信息。它提供了丰富的功能和灵活性,使开发人员能够轻松地记录各种类型的日志,并将其输出到不同的目标,包括日志文件。本文将详细介绍Microsoft.Extensions.Logging的各种基础功能以及如何按

    2024年02月05日
    浏览(48)
  • 【Microsoft Visual Studio安装问题】Microsoft.VisualStudio.Setup.Configuration

    成功撒花 ~~~ 真的太不容易了 ~ 在安装visual studio的过程中真的状况百出,通过查看日志找到 系统策略禁止安装此设备,请与系统管理员联系 因此赶紧百度这个问题。。。 百度上有很多关于这个问题的解决方法,尝试了很多种但都不太完全,最终解决方法如下: 点击win+R输入

    2024年02月12日
    浏览(46)
  • Install Microsoft Endpoint Configuration Manager

    In my last article about Attack Surface Reduction, I didn’t care enough to go through all the documentation and went for a long detour to install Microsoft Endpoint Configuration Manager for Attack Surface Reduction configurations. It turned out that, all I need is Group Policy. So, this article, I moved the part of installing Microsoft Endpoint Configurat

    2024年02月04日
    浏览(70)
  • 使用Newtonsoft直接读取Json格式文本(Linq to Json)

    使用 Newtonsoft.Json(通常简称为 Newtonsoft)可以轻松地处理 JSON 格式的文本。Newtonsoft.Json 是 .NET 中一个流行的 JSON 处理库,它提供了丰富的功能和灵活性。 以下是使用 Newtonsoft.Json 进行 Linq to JSON 的示例代码: 首先,你需要在项目中安装 Newtonsoft.Json 包。你可以通过 NuGet 包管理

    2024年02月16日
    浏览(59)
  • 使用pandas读取HTML和JSON数据

    大家好,Pandas是一个功能强大的数据分析库,它提供了许多灵活且高效的方法来处理和分析数据。本文将介绍如何使用Pandas读取HTML数据和JSON数据,并展示一些常见的应用场景。 HTML(超文本标记语言)是一种用于创建网页的标准标记语言。网页通常由HTML标签和内容组成,这

    2024年01月18日
    浏览(36)
  • 【Python】使用Python读取JSON文件中的内容

    在自动化测试过程中,会将部分数据保存到JSON文件中。 JSON文件有以下特点: JSON是存储和交换文本信息的语法,类似XML。 JSON比XML更小、更快、更易解析 JSON是轻量级的文本数据交换格式。 JSON是轻量级的文本数据交换格式。 JSON独立于语言 JSON具有自我描述性、更易理解。

    2024年02月13日
    浏览(51)
  • Python:使用openpyxl读取Excel文件转为json数据

    openpyxl - A Python library to read/write Excel 2010 xlsx/xlsm files 文档 https://openpyxl.readthedocs.io/en/stable/ https://pypi.org/project/openpyxl/ 安装 环境 读取文件示例:将Excel文件读取为json数据 有如下一个文件 data.xlsx 实现代码 输出读取的json数据 读写示例

    2024年02月15日
    浏览(73)
  • C#中LINQtoSQL只能在.NetFramework下使用,不能在.net 下使用

    目录 一、在net7.0下无法实现LINQtoSQL 1.VS上建立数据库连接 2.VS上创建LINQtoSQL 二、在.NetFramework4.8下成功实现LINQtoSQL 1.VS上建立数据库连接 2.VS上创建LINQtoSQL 三、结论 四、理由         本文是个人观点,因为我百般努力在.net7.0下无法实现LINQtoSQL的使用,而在.NetFramework4.8却能

    2024年02月06日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包