C#Json读写数据

#region//Json参数类
 public class CameraParameters
    {
        /// <summary>
        /// 相机名字
        /// </summary>
        public string CameraName { get; set; }
        /// <summary>
        /// 相机序列号
        /// </summary>
        public string CameraSerialNum { get; set; }
        /// <summary>
        /// 相机曝光时间
        /// </summary>
        public double CameraExposure { get; set; }
        /// <summary>
        /// 相机序触发模式
        /// </summary>
        public string CameraTriggerMode { get; set; }
        /// <summary>
        /// COM口名字
        /// </summary>
        public string COMName { get; set; }
        /// <summary>
        /// 机器人通信协议是否启用
        /// </summary>
        public bool RobotCommunicationEnable { get; set; }
        /// <summary>
        /// 机器人通信协议
        /// </summary>
        public string RobotCommunicationType { get; set; }
        /// <summary>
        /// 机器人通信IP地址
        /// </summary>
        public string RobotCommunicationIP { get; set; }
        /// <summary>
        /// 机器人通信IP地址
        /// </summary>
        public int RobotCommunicationPort { get; set; }
        /// <summary>
        /// PLC通信协议是否启用
        /// </summary>
        public bool PLCCommunicationEnable { get; set; }
        /// <summary>
        /// PLC通信协议
        /// </summary>
        public string PLCCommunicationType { get; set; }
        /// <summary>
        /// PLC通信IP地址
        /// </summary>
        public string PLCCommunicationIP { get; set; }
        /// <summary>
        /// PLC通信IP地址
        /// </summary>
        public int PLCCommunicationPort { get; set; }
        /// <summary>
        /// 实时图像是否显示十字线
        /// </summary>
        public bool IsShowCrosshair { get; set; }
        /// <summary>
        /// 相机生产的配方名称
        /// </summary>
        public string ProductName { get; set; }
        /// <summary>
        /// 相机像素Width
        /// </summary>
        public int CameraWidthPixel { get; set; }
        /// <summary>
        /// 相机像素Height
        /// </summary>
        public int CameraHeightPixel { get; set; }
        /// <summary>
        /// 总共工站
        /// </summary>
        public int StationNumber { get; set; }
    }
    #endregion
string paht = @"C:\Users\WFQ\source\repos\ConsoleApp3\ConsoleApp3\bin\Debug\1.json";  
 List<CameraParameters> cameraParameters = new List<CameraParameters>();//Json类集合
cameraParameters = JsonConvert.DeserializeObject<List<CameraParameters>>(File.ReadAllText(paht));//把json文件信息返回集合
[
  {//Json格式集合
    "CameraName": "钢板定位相机",
    "CameraSerialNum": "00F00225061",
    "CameraExposure": 5,
    "CameraTriggerMode": "Manual",
    "COMName": null,
    "RobotCommunicationEnable": false,
    "RobotCommunicationType": null,
    "RobotCommunicationIP": "192.168.1.222",
    "RobotCommunicationPort": 5555,
    "PLCCommunicationEnable": false,
    "PLCCommunicationType": null,
    "PLCCommunicationIP": null,
    "PLCCommunicationPort": 0,
    "IsShowCrosshair": false,
    "ProductName": "YP20201204",
    "StationNumber": 3
  },
{
    "PLCCommunicationPort": 0,
    "IsShowCrosshair": false,
    "ProductName": "YP20201204",
    "StationNumber": 3
  }
]
using Newtonsoft.Json;//命名空间
File.WriteAllText(paht, JsonConvert.SerializeObject(cameraParameters ,Formatting.Indented));//Json写数据
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值