#region
public class CameraParameters
{
public string CameraName { get; set; }
public string CameraSerialNum { get; set; }
public double CameraExposure { get; set; }
public string CameraTriggerMode { get; set; }
public string COMName { get; set; }
public bool RobotCommunicationEnable { get; set; }
public string RobotCommunicationType { get; set; }
public string RobotCommunicationIP { get; set; }
public int RobotCommunicationPort { get; set; }
public bool PLCCommunicationEnable { get; set; }
public string PLCCommunicationType { get; set; }
public string PLCCommunicationIP { get; set; }
public int PLCCommunicationPort { get; set; }
public bool IsShowCrosshair { get; set; }
public string ProductName { get; set; }
public int CameraWidthPixel { get; set; }
public int CameraHeightPixel { get; set; }
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>();
cameraParameters = JsonConvert.DeserializeObject<List<CameraParameters>>(File.ReadAllText(paht));
[
{
"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));